What would be the equivalent to this using apply family functions or a compbination between do.call and apply? I would like to keep it simple and when possible in one line:
a <- list( as.data.frame(matrix(rnorm(12),4,3)),
as.data.frame(matrix(rnorm(12),4,3)),
as.data.frame(matrix(rnorm(12),4,3))
)
l <- list()
for (i in 1:length(a)) {
l[[i]] <- apply(a[[i]],1,max)
}
b <- do.call(data.frame, l)
I would use
sapplyfor this particular example, however I don't know how representative this example is of your actual larger problem.sapplywill simplify to a matrix whenever possible. If you want adata.frame, just wrap the output indata.frame.