[R] Sampling question

Chris Mcowen cm744 at st-andrews.ac.uk
Mon Jan 17 16:31:59 CET 2011


Dear list i have a sample question

I have a dataframe of 1500 species and 13 life history traits. 

small example code:

traits <- 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(traits) <- c("species", 1:8)

What i want to do is:

Sample a number of species from the data frame in integers of 50: -  50 species, 100 species ,150,200... up-to 1500, when i sample them i also want the traits associated with them to be kept intact. For each species number i would like a 1000 repetitions. So i would like 50 species with their life history traits randomly sampled 1000 times, then 100 species with their life history traits sampled 1000 times. I appreciate that as i get to the higher numbers i.e 1500 species this will only be sampled once, therefore i will need to use replace = yes.

Then i have a function i want to run on the sample so for the 50 species  i want to run a function which requires the name of the sample

GFD(50species_sample1)
GFD(50species_sample2) etc to 
GFD(50species_sample1000)

Then 

GFD(100species_sample1)

etc.
With the reults put into a data-frame.

I am relatively new to R, i could probably hack together a code but i am unsure how to join it up so i sample, retain the data and then use it in a function?

Any help would be greatly appreciated.

I appreciate this is a lot to ask so any help would be greatly appreciated.

Thanks in advance,

Chris



More information about the R-help mailing list