Try this:

replicate(500, example[sample(nrow(example), 3),], simplify = FALSE)


On Fri, Jan 21, 2011 at 8:47 AM, Sam <Sam_Smith@me.com> wrote:

> Dear List,
>
> I have a data-frame
>
> #prepare the data
> example <- data.frame(letters[1:9],
>       sample(letters, 9),
>       sample(letters, 9),
>       sample(letters, 9),
>       sample(letters, 9),
>       sample(letters, 9),
>       sample(letters, 9),
>       sample(letters, 9),
>       sample(letters, 9))
> colnames(example) <- c("individuals", 1:8)
>
> I want to sample this
>
> #sample the data
> a_1 <- example[sample(nrow(example),3),]
>
> individuals 1 2 3 4 5 6 7 8
> 8           h w m r a n v v b
> 6           f e b g u v r b p
> 3           c z c s k t e i g
>
> However i want to sample it 500 times, so i need to use the loop function -
> which is something, unfortunately i am unsure how to write.
>
> Furthermore, i want to output the results in a data-frame ( i think i need
> the list function, but again i am unsure)
>
> Ideally it would be separated by sample but i am unsure if this is
> possible? However as long as the order is kept intact that will be fine. I.E
> the top 3 are sample 1, the next 3 are sample 2 etc
>
> What i require:-
>
> individuals 1 2 3 4 5 6 7 8
>
> 8                    h w m r a n v v b
> 6                   f e b g u v r b p
> 3                   c z c s k t e i g
>
> 9                   h w m f a n v v b
> 4                   f e b g b v r b p
> 2                   c z c s k t e i g
>
> If its not too much to ask: I will then sample it 4 individuals 500 times ,
> 5 individuals etc etc and store these _ i can always do these separately if
> its asking too much!
>
> Thanks,
>
> Sam
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

