ftable
is nice to produce flat tables. But it does accept nothing but a n-dim table (resp. array) as argument.
So Mbind
binds two (or n) r x c matrices to one 3-dimensional n x r x c table(array), which can be passed to ftable to produce flat tables.Mbind(...)
CatTable
, matrix
m1 <- do.call("rbind", lapply( d.pizza[,c("delivery_min","temperature")],
tapply, d.pizza$area, mean, na.rm=TRUE))
names(dimnames(m1)) <- c("vname","area")
m2 <- do.call("rbind", lapply( d.pizza[,c("delivery_min","temperature")],
tapply, d.pizza$area, median, na.rm=TRUE))
names(dimnames(m2)) <- c("vname","area")
m3 <- do.call("rbind", lapply( d.pizza[,c("delivery_min","temperature")],
tapply, d.pizza$area, sd, na.rm=TRUE))
names(dimnames(m3)) <- c("vname","area")
m <- Mbind(mean=m1, median=m3, sd=m2)
m
class(m)
ftab <- round(ftable(m, col.vars=c("area")),2)
ftab
# two different classes
Mbind( alpha=matrix(letters[1:4], nrow=2), num=matrix(1:4, nrow=2))
# matrices with different dimensions are not allowed, following would raise an error:
# Mbind( matrix(letters[1:4], nrow=2), matrix(1:9, nrow=3))
Run the code above in your browser using DataLab