title: “Random samples from R data frames.” date: 2013-06-09 categories:
- “r”
There are times you just have too much data, random samples are nice to test assumptions and algorithms first.
So in R you can create a function to return a random sample of a data frame for such emergencies.
randomSample = function(df,n) { 
   return (df[sample(nrow(df), n),])
}
And to use:
smallerDF<-randomSample(bigDF, 40)
(40 being the number of rows you want in your sample).