[R] Sampling in R

2006-03-23 Thread Noam Friedman
Hi all! I was wondering if you can help me with a little sampling issue I'm having in R. I have a database with 100 observations. I need to sample n=9 sample size, 200 times (i.e. get 200 samples of size 9). N (pop. size) =100 Each sample can't contain the same observation more than one tim

Re: [R] Sampling in R

2006-03-23 Thread Thomas Petzoldt
Does the following what you want: x <- 1:100 s <- matrix(0, nrow=200, ncol=9) for (i in 1:200) { s[i, ] <- sample(x, 9) } m <- rowMeans(s) hist(m) The default behavior of sample is without replacement. Thomas Noam Friedman wrote: > > Hi all! > > > > > > I was wondering if you can help me w

Re: [R] Sampling in R

2006-03-23 Thread Sean Davis
On 3/23/06 5:52 AM, "Noam Friedman" <[EMAIL PROTECTED]> wrote: > Hi all! > > > I was wondering if you can help me with a little sampling issue I'm > having in R. > > I have a database with 100 observations. > I need to sample n=9 sample size, 200 times (i.e. get 200 samples of > size 9). > N

Re: [R] Sampling in R

2006-03-23 Thread pedro caƱadilla
I prefer the function resample as it is given in the sample help, in this way: resample <- function(x, size, ...) { if length(x <= 1) {if (!missing(size) && size == 0) x[FALSE] else x} else sample(x, size, ...) } Anyway, if an observation can not be twice in the sample, you have to use replace=

Re: [R] Sampling in R

2006-03-23 Thread Liaw, Andy
From: Sean Davis > > On 3/23/06 5:52 AM, "Noam Friedman" <[EMAIL PROTECTED]> wrote: > > > Hi all! > > > > > > I was wondering if you can help me with a little sampling issue I'm > > having in R. > > > > I have a database with 100 observations. > > I need to sample n=9 sample size, 200 times (