I have a dataframe in R with three variables named for example df$V1
, df$V2
, df$V3
.
df$V1
and df$V2
are both
This is an alternative to table
:
xtabs(V3 ~ V1 + V2, df)
As mentioned by ran2, you can use the reshape
package. Here is an example:
df <- data.frame(V1 = factor(sample(letters[1:5],100,replace=TRUE)),
V2 = factor(toupper(sample(letters[1:5],100,replace=TRUE))),
V3 = runif(100))
library(reshape)
cast(df, V1 ~ V2, mean)