Re: [R] Randomly drop a percent of data from a data.frame

2013-08-16 Thread Richard Kwock
Try this: data <- data.frame(x1=rnorm(5),x2=rnorm(5),x3=rnorm(5),x4=rnorm(5)) data <- round(data,digits=3) #get the total counts n = prod(dim(data)) #set up a dummy array/matrix dummy <- rep(F, n/2) dummy[sample(1:(n/2), n*.2)] <- T # 5x2 dummy matrix with T and F matrix(dummy, nc = 2) #subset

Re: [R] Randomly drop a percent of data from a data.frame

2013-08-16 Thread Christopher Desjardins
Hi, Thanks for the help. What I actually ended up doing was writing a copy of for loops and I ended up getting something works. Thanks. Chris On Fri, Aug 16, 2013 at 4:34 PM, arun wrote: > Hi, > May be this helps: > #data1 (changed `data` to `data1`) > set.seed(6245) > data1 <- data.frame(x1=r

Re: [R] Randomly drop a percent of data from a data.frame

2013-08-16 Thread arun
NA #3 -1.09734838  0.2069539 -0.6997853 #4  0.75919499 -0.5683809  0.4752002 #5 -0.03063141 -0.7549605  2.6038635 A.K. From: Richard Kwock To: arun Cc: Christopher Desjardins ; R help Sent: Friday, August 16, 2013 5:55 PM Subject: Re: [R] Randomly drop a

Re: [R] Randomly drop a percent of data from a data.frame

2013-08-16 Thread arun
Hi, May be this helps: #data1 (changed `data` to `data1`) set.seed(6245)  data1 <- data.frame(x1=rnorm(5),x2=rnorm(5),x3=rnorm(5),x4=rnorm(5))  data1<- round(data1,digits=3) data2<- data1 data1[,3:4]<-lapply(data1[,3:4],function(x){x1<- match(x,sample(unlist(data1[,3:4]),round(0.8*length(unlist(