[R] find the corresponding mean y
    Greg Hirson 
    ghirson at ucdavis.edu
       
    Mon Jan 11 19:59:34 CET 2010
    
    
  
Annie,
If I understand what you are asking, you want to sample some number of 
observations, with replacement, then find the mean of x and y for those 
observations.
In this case, you would want to sample the row indices instead of the 
values. For example,
     #test data
set.seed(1)
df <- data.frame(x = rnorm(100), y = rnorm(100))
     #sample from row indices
samp <- sample(nrow(df), 25, replace = TRUE)
     #get means for x and y
mean(df[samp,]$x)
mean(df[samp,]$y)
     #or
mean(df[samp,])
Greg
On 1/11/10 9:42 AM, luciferyan wrote:
> Hello, I have 49 paired data, x, y.
> I have sampled x (where replacement is true), and find its mean.
> How can I find the corresponding mean y, which is the paired data of above
> sample x?
> Thank you very much,
> Annie
>    
-- 
Greg Hirson
ghirson at ucdavis.edu
Graduate Student
Agricultural and Environmental Chemistry
1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616
    
    
More information about the R-help
mailing list