Taking some generic data
set.seed(123)
A <- sample(1997:2000, 50, replace=TRUE)
B <- sample(1:3, 50, replace=TRUE)
C <- rnorm(50)
df <- data.frame(A,B,C)
I want to create a summary table that for each A
value (year), and then each B
value (type), will print the corresponding median C
value
I have tried the following code
in reference to this website
mytable <- table(df$A, df$B, median(df$C))
ftable(mytable)
and here
require(plyr)
ddply(df, .(A), summarize,
type=unique(B),
median=median(C))
but neither seems to work. The desired output should look similar to this: