I would like to run a t-test within a "by" group function. My  
dataset, "error",  is organized as the following (I have 133 Sites):

Site week Dataset Region  lat_map  long_map mean_tsim diff20 diff40  
diff80
ALFI   15   USACE     UC 48.15625 -117.0938      8.87   1.34   1.90    
2.98
ALFI   16   USACE     UC 48.15625 -117.0938     10.28   0.57   1.08    
2.27
ALFI   17   USACE     UC 48.15625 -117.0938     11.08   0.74   1.30    
2.52
ALFI   18   USACE     UC 48.15625 -117.0938     12.23   0.42   1.11    
2.42
ALFI   19   USACE     UC 48.15625 -117.0938     13.19   1.00   1.73    
3.14
ALFI   20   USACE     UC 48.15625 -117.0938     14.31   1.77   2.62    
3.78

I am interested in running the t-test by the "Site" index. My code  
looks like this:

t_test<-by(error, error['Site'], function(dat) t.test(subset(error 
$diff20),subset(error$diff80), data=dat))

This code runs the t-test, but over the whole dataset without  
discriminating by Site, so each Site's result is the same. Could  
someone help determine a better approach or why mine is not working.
Thank you,
Ingrid


        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to