Could anyone tell me how,from a pool of 1002 observations (one variable), can I resample 1000 samples of 20 observations? And then calculate the mean and standard deviation between 2, 3, 4, ..., 1000 samples and plot them? Thank you! _____________________________________ Rita Gamito Centro de Oceanografia Faculdade de Ci?ncias, Universidade de Lisboa Campo Grande, 1749-016 Lisboa, Portugal e-mail: rgamito at fc.ul.pt Tel: + 351 21 750 00 00 - ext. 22575 Fax: + 351 21 750 02 07 www.co.fc.ul.pt
Hi. See ?sample, ?replicate,?colMeans, ?plot.. Here is the simple example: sample(1:1000,20) replicate(5, sample(1:1000,20)) colMeans(replicate(5, sample(1:1000,20))) Andrija On Wed, Jul 31, 2013 at 1:23 PM, Rita Gamito <rslopes@fc.ul.pt> wrote:> Could anyone tell me how,from a pool of 1002 observations (one variable), > can I resample 1000 samples of 20 observations? > And then calculate the mean and standard deviation between 2, 3, 4, ..., > 1000 samples and plot them? > Thank you! > > _____________________________________ > > Rita Gamito > Centro de Oceanografia > Faculdade de Ciências, Universidade de Lisboa > Campo Grande, 1749-016 Lisboa, Portugal > e-mail: rgamito@fc.ul.pt > Tel: + 351 21 750 00 00 - ext. 22575 > Fax: + 351 21 750 02 07 > www.co.fc.ul.pt > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hello, The best way seems to be ?replicate. set.seed(3997) # make it reproducible x <- rnorm(1002) # make up some data sim <- replicate(1000, sample(x, 20)) colSds <- function(x, na.rm = FALSE) apply(x, 2, sd, na.rm = na.rm) mu <- colMeans(sim) sigma <- colSds(sim) Hope this helps, Rui Barradas Em 31-07-2013 12:23, Rita Gamito escreveu:> Could anyone tell me how,from a pool of 1002 observations (one variable), can I resample 1000 samples of 20 observations? > And then calculate the mean and standard deviation between 2, 3, 4, ..., 1000 samples and plot them? > Thank you! > > _____________________________________ > > Rita Gamito > Centro de Oceanografia > Faculdade de Ci?ncias, Universidade de Lisboa > Campo Grande, 1749-016 Lisboa, Portugal > e-mail: rgamito at fc.ul.pt > Tel: + 351 21 750 00 00 - ext. 22575 > Fax: + 351 21 750 02 07 > www.co.fc.ul.pt > ______________________________________________ > 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. >
Thank you! I have used the replicate function. In fact, I had just found the solution when I received your answers. Best regards, Rita _____________________________________ Rita Gamito Centro de Oceanografia Faculdade de Ci?ncias, Universidade de Lisboa Campo Grande, 1749-016 Lisboa, Portugal e-mail: rgamito at fc.ul.pt Tel: + 351 21 750 00 00 - ext. 22575 Fax: + 351 21 750 02 07 www.co.fc.ul.pt