Random sampling of two vectors, finding mean of sample, then making a matrix in R? -


thanks time!

my data frame simple. 2 columns: first has genotype (1-39) , second has trait values (numerical, continuous). choose 8 genotypes , calculate mean , stdev of associated trait values.

in end sample 8 genotypes 10,000 times , each sample have stdev , mean of associated trait values. ideally in matrix each row represented sample, 8 columns each genotype, , 2 final columns stdev , mean of trait values associated genotypes. oriented other way too.

  1. how sample 2 different columns in data frame both values show in new sample? i.e genotypes , trait values mean , stdev calculated

  2. how sample matrix i've described above?

  3. how repeat process 10,000 times?

thanks again!

this return single sample of rows genotype in random sample of 8 traits:

dat[ dat$genotype %in% sample(1:39, 8), ] 

the replicate function designed repeat random process. repeat 3 times getting sd of "trait" such sample of 2 genotypes:

dat <- data.frame(genotype=sample(1:5, 25,replace=true), trait=rnorm(25) ) replicate ( 3, sd(dat[ dat$genotype %in% sample(1:5, 2), "trait" ]) ) [1] 0.7231686 0.9225318 0.9225318 

this records sample ids means , sd values:

replicate ( 3, {c( samps =sample(1:5, 2),                     sds=sd(dat[ dat$genotype %in% samps, "trait" ]) ,                    means = mean(dat[ dat$genotype %in% samps, "trait" ]) )} )             [,1]      [,2]      [,3] samps1 1.0000000 1.0000000 5.0000000 samps2 5.0000000 3.0000000 1.0000000 sds    0.8673977 0.8673977 0.8673977 means  0.2835325 0.2835325 0.2835325 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -