Re: [R-sig-eco] Problem in generate random samples in r
My guess would be that absences_15 doesn't have 1 rows. Can you confirm or refute this? Cheers, Roman On Wed, Feb 20, 2019 at 12:20 PM Lara Silva wrote: > Hello, > > I am trying to generate random samples from the following code > > ### Setting random seed to always create the same > ### Random set of points > set.seed(0) > > absences_15000<-absences[sample(nrow(absences), 15000),] > points(absences_15000, cex=0.1) > > ## Subsample_1 > set.seed(0) > > absences_1<-absences_15000[sample(nrow(absences_15000), 1),] > dim(absences_1) > > I get the following error: > > Error in sample.int(length(x), size, replace, prob) : > cannot take a sample larger than the population when 'replace = FALSE' > > Any advice? > > Regards, > > Lara > > [[alternative HTML version deleted]] > > ___ > R-sig-ecology mailing list > R-sig-ecology@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > -- In God we trust, all others bring data. [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Problem in generate random samples in r
Thanks! Lara Henrik Eckermann escreveu no dia quarta, 20/02/2019 à(s) 10:25: > Hi Lara, > > the error is quite informative. You use the sample function twice. At > least for one the length of the vector where you sample from is shorter > (contains less values) than than the number of samples you wanna draw. > > best, > > Henrik > > > On 20. Feb 2019, at 12:20, Lara Silva wrote: > > > > Hello, > > > > I am trying to generate random samples from the following code > > > > ### Setting random seed to always create the same > > ### Random set of points > > set.seed(0) > > > > absences_15000<-absences[sample(nrow(absences), 15000),] > > points(absences_15000, cex=0.1) > > > > ## Subsample_1 > > set.seed(0) > > > > absences_1<-absences_15000[sample(nrow(absences_15000), 1),] > > dim(absences_1) > > > > I get the following error: > > > > Error in sample.int(length(x), size, replace, prob) : > > cannot take a sample larger than the population when 'replace = FALSE' > > > > Any advice? > > > > Regards, > > > > Lara > > > > [[alternative HTML version deleted]] > > > > ___ > > R-sig-ecology mailing list > > R-sig-ecology@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > > [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Problem in generate random samples in r
Hi Lara, the error is quite informative. You use the sample function twice. At least for one the length of the vector where you sample from is shorter (contains less values) than than the number of samples you wanna draw. best, Henrik > On 20. Feb 2019, at 12:20, Lara Silva wrote: > > Hello, > > I am trying to generate random samples from the following code > > ### Setting random seed to always create the same > ### Random set of points > set.seed(0) > > absences_15000<-absences[sample(nrow(absences), 15000),] > points(absences_15000, cex=0.1) > > ## Subsample_1 > set.seed(0) > > absences_1<-absences_15000[sample(nrow(absences_15000), 1),] > dim(absences_1) > > I get the following error: > > Error in sample.int(length(x), size, replace, prob) : > cannot take a sample larger than the population when 'replace = FALSE' > > Any advice? > > Regards, > > Lara > > [[alternative HTML version deleted]] > > ___ > R-sig-ecology mailing list > R-sig-ecology@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
[R-sig-eco] Problem in generate random samples in r
Hello, I am trying to generate random samples from the following code ### Setting random seed to always create the same ### Random set of points set.seed(0) absences_15000<-absences[sample(nrow(absences), 15000),] points(absences_15000, cex=0.1) ## Subsample_1 set.seed(0) absences_1<-absences_15000[sample(nrow(absences_15000), 1),] dim(absences_1) I get the following error: Error in sample.int(length(x), size, replace, prob) : cannot take a sample larger than the population when 'replace = FALSE' Any advice? Regards, Lara [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology