Hayes, Rachel M
2009-Nov-13 22:20 UTC
[R] help sample from large dataset - misleading error?
Hi All, I want to take a simple random sample from a large dataset, gly, but I'm getting an error message. Any help? dim(gly) [1] 112371 37> s1 <- sample(gly,100)Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, : cannot take a sample larger than the population when 'replace = FALSE' Thanks, Rachel [[alternative HTML version deleted]]
Rachel, The first thing to do when a function gives you trouble is to look at its help page. In the case of sample(), you will find that it requires a *vector* input. Is your gly a vector? -Peter Ehlers Hayes, Rachel M wrote:> Hi All, > > > > I want to take a simple random sample from a large dataset, gly, but I'm > getting an error message. Any help? > > > > dim(gly) > > [1] 112371 37 > >> s1 <- sample(gly,100) > > Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, : > > > cannot take a sample larger than the population when 'replace = FALSE' > > > > Thanks, > > > > Rachel > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > >
Jorge Ivan Velez
2009-Nov-14 00:46 UTC
[R] help sample from large dataset - misleading error?
Hi Rachel, Here is a suggestion: index <- sample(100) mysample <- gly[index, ] mysample See ?sample for more information. HTH, Jorge On Fri, Nov 13, 2009 at 5:20 PM, Hayes, Rachel M <> wrote:> Hi All, > > > > I want to take a simple random sample from a large dataset, gly, but I'm > getting an error message. Any help? > > > > dim(gly) > > [1] 112371 37 > > > s1 <- sample(gly,100) > > Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, : > > > cannot take a sample larger than the population when 'replace = FALSE' > > > > Thanks, > > > > Rachel > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]