Hi List,

I am trying to randomise a dataframe with mixed factors/numeric
variables and return a new (randomised) dataframe with the same columns
(as factors/numeric).

simgap<-function(x) {
 ma<-max(x)
 mi<-min(x)
 Xout<-runif(length(x),min=mi,max=ma)
 return(Xout) }



rdize.dta<-function(x){
                   if(is.factor(x)) {
                   cat(str(x),"\n")
 
factor(as.character(round(runif(n=length(x),min=1,max=nlevels(xx)),0)))}
                   else if(is.integer(x)) round(simgap(x),0)
                   else if(is.numeric(x)) simgap(x)
                   else x<-c("Error, not factor/numeric")
                   return(x)
                   }

sapply(warpbreaks,FUN=function(x) rdize.dta(x))->test

str(test)

While I could to this in a loop, I am unable to do this with sapply.

Any suggestions?

Thanks
Herry

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to