[R] tapply to data.frame or matrix

2012-09-04 Thread Jannis
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

Re: [R] tapply to data.frame or matrix

2012-09-04 Thread Rui Barradas
Hello, Here's a way. test - as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind - c(1,1,2,2,2) lapply(split(colnames(test), test.ind), function(x) unlist(test[, x])) Hope this helps, Rui Barradas Em 04-09-2012 15:40, Jannis escreveu: Dear R users, imagine i have a dataframe and an

Re: [R] tapply to data.frame or matrix

2012-09-04 Thread arun
: Re: [R] tapply to data.frame or matrix Hello, Here's a way. test - as.data.frame(matrix(1:20, ncol = 5, nrow=4)) test.ind - c(1,1,2,2,2) lapply(split(colnames(test), test.ind), function(x) unlist(test[, x])) Hope this helps, Rui Barradas Em 04-09-2012 15:40, Jannis escreveu: Dear R users