The by function from base R has its own special output class, "by", which comes with a special print format. For ease of putting the results into tables, I'd really like to arrange the results of "by" as a data frame with columns indicating the levels of the factors used to subset:
b <- by(mtcars$mpg, list(mtcars$vs, mtcars$am), function(x) c(length(x), mean(x)))
some_reformatting_function(b)
# am vs length mean
#1 0 0 12 15.05000
#2 0 1 7 20.74286
#3 1 0 6 19.75000
#4 1 1 7 28.37143
When the FUN argument to by is of length one, I can hack this together by forcing the class of b to be numeric, then melting. But when FUN retus a longer vector, this approach doesn't work. Any suggestions?
