[R] Using apply for two datasets
Christos Argyropoulos
argchris at hotmail.com
Fri Jan 9 00:56:46 CET 2009
It depends on how the data are arranged
##----------------------------------------------------
x<-matrix(c(1,2,3,2,8,2,4,5,6),nrow=3)
y<-matrix(c(10,2,13,0,8,4,4.2,5.2,6.2),nrow=3)
q<-mapply(t.test,as.data.frame(x),as.data.frame(y))
q
## The ith column of q contain the results of applying t.test to
## the ith column of x and the jth column of y
##----------------------------------------------------
Since the t.test returns a list, you can wrap it in your own function if
you want to process the data in an assembly line fashion.
Continuing the previous example:
my.t<-function(x,y,...) { c(t.test(x,y,...))[1:3] }
q2<-mapply(my.t,as.data.frame(x),as.data.frame(y))
q2
Good luck!
Christos Argyropoulos
University of Pittsburgh Medical Center
More information about the R-help
mailing list