[R] tapply to data.frame or matrix

Jannis bt_jannis at yahoo.de
Tue Sep 4 16:40:33 CEST 2012


Dear R users, 


imagine i have a dataframe and an indexing vector with the length of the 
amount of columns of the dataframe. Is there any convenient way to 
combine the colums of the dataframe into vectors (or straight away apply 
fundtions to these subsets) according to the indexing vector in a 
similar manner to the tapply function? 

For example, in the follwoing case, I would like to combine columns 1 
and two into one vector, and columns 3-4 into another: 

test     = as.data.frame(matrix(1:20, ncol = 5, nrow=4)) 
test.ind =c(1,1,2,2,2) 


Thanks a lot! 
Jannis



More information about the R-help mailing list