Error In .data.frame X .internalsamplelengthx Size Replace
Contents |
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us k means cannot take a sample larger than the population when 'replace = false' Learn more about Stack Overflow the company Business Learn more about hiring developers
R Error In Sample.int(m, K) : Cannot Take A Sample Larger Than The Population When 'replace = False'
or posting ads with us Cross Validated Questions Tags Users Badges Unanswered Ask Question _ Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Resampling without replacement in R, with a loop up vote 2 down vote favorite Here is the head of my data set (tjornres): Fish.1 Fish.2 MORPHO DIET 1 1 2 0.03768 0.1559250 2 1 3 0.05609 0.7897060 3 1 4 0.03934 0.4638010 4 1 5 0.03363 0.1200480 5 1 6 0.05629 0.4390760 6 1 8 0.08366 0.1866750 7 1 9 0.04892 0.0988235 8 1 10 0.04427 0.2637140 MORPHO and DIET refer to the morphological and diet distances between fish 1 and fish 2. My original data set has over 2400 pairs of fish. My goal is to resample this dataset by selecting only 435. I would like to do this 999 times and get a distribution of the correlation coefficients MORPHO~DIET. I went on and wrote this code: head(tjornres) essayres = tjornres # copy of the data R = 999 # the number of replicates cor.values = numeric(R) # store the data for (i in 1:R) { # loop + group1 = sample(essayres, size=435, replace=F) + group2 = sample(essayres, size=435, replace=F) + cor.values[i] = cor.test(group1,group2)$cor + } I have a syntax error in this code. Also if I run one resampling, sample(essayres, size=435, replace=F), I get this error message: Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, :cannot take a sample larger than the population when 'replace = FALSE'. Does anyone know why this code is not working? Are there any other ways to resample (without replacement) ? Thank you for your help, r correlation resampling share|improve this question edited Feb 20 '12 at 16:58 Andy
Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ 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 http://stats.stackexchange.com/questions/23173/resampling-without-replacement-in-r-with-a-loop deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Peter Ehlers Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: help sample from large dataset - misleading error? Rachel, The first thing to do when a function gives you trouble is to look at its help http://r.789695.n4.nabble.com/help-sample-from-large-dataset-misleading-error-td908933.html 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]] > > ______________________________________________ > [hidden email] 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. > > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Jorge I Velez Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: help sample from large dataset - mislea
by: [ date ] [ thread ] [ subject ] https://stat.ethz.ch/pipermail/r-help/2008-August/171843.html [ author ] Hi, I find convenient to use a custom function for this: sample.df <- function (df, N = 1000, ...) { df[sample(nrow(df), N, ...), ] } sample.df(daf1,1000) Hope this helps, baptiste On 25 Aug 2008, at 12:31, Martin Hvidberg wrote: > > > I have a data frame error in (daf1), that holds +80000 records, and 10 > variables (i.e. 10 columns and some 80000 rows) > >> length(daf1) > [1] 10 >> length(daf1[,1]) > [1] 83805 > > I would like to sample() e.g. 10000 records from this. I use: > >> daf2 <- sample(daf1, 1000, replace = FALSE, prob cannot take a = NULL) > Error in `[.data.frame`(x, .Internal(sample(length(x), size, > replace, : > cannot take a sample larger than the population when 'replace = > FALSE' > > As length(daf1) is 10, it thinks I'm taking 10000 samples from a > size 10 population... Arghhh > > How do I go about sampeling from a data frame? > > :-( Martin > > ______________________________________________ > 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. _____________________________ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag Previous message: [R] Using sample() with a data frame ? Next message: [R] Odp: Using sample() with a data frame ? Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] More information about the R-help mailing list