Skip to content

Beginner-how to down size a large sample

2 messages · pramil cheriyath, Gustaf Rydevik

#
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.
#
On Wed, Feb 11, 2009 at 3:15 PM, pramil cheriyath <drpramil at gmail.com> wrote:
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....)