Skip to content

Sampling question

2 messages · Chris Mcowen, PIKAL Petr

#
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
#
Hi

It is rather unclear how do you want sample your data. It seems to me that 
you can  sample row numbers and choose sampled rows from data frame.

I probably direct output to a list ("mylist") and use

result <- lapply("mylist", GFD)

Regards
Petr



r-help-bounces at r-project.org napsal dne 17.01.2011 16:31:59:
want
number i
life
life
higher
will need
i
a function?
appreciated.
http://www.R-project.org/posting-guide.html