I have this large data set with an outcome variable 0 and 1, I want to randomly pick 100 from each group and create another data set.
Beginner-how to down size a large sample
2 messages · pramil cheriyath, Gustaf Rydevik
On Wed, Feb 11, 2009 at 3:15 PM, pramil cheriyath <drpramil at gmail.com> wrote:
I have this large data set with an outcome variable 0 and 1, I want to randomly pick 100 from each group and create another data set.
______________________________________________ R-help at r-project.org 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.
dataSet<-data.frame(group=sample(c(1,0),10000,replace=T),data=rnorm(10000)) dataSet.1<-dataSet[dataSet$group==1,] dataSet.0<-dataSet[dataSet$group==0,] sampled.1<-dataSet.1[sample(1:nrow(dataSet.1),100),] sampled.0<-dataSet.0[sample(1:nrow(dataSet.0),100),] newdataSet<-rbind(sampled.1,sampled.0) /Gustaf (a "please", would have been nice....)
Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik