我在R中的以下小例子:获取的多个变量/列分类因子数中的R
testing = data.frame(c("Once a week", "Once a week", "Rarely", "Once a month", "Once a month"), c("Once a month", "Once a month", "Once a week", "Rarely", "Rarely"))
colnames(testing) = c("one", "two")
testing
one two
1 Once a week Once a month
2 Once a week Once a month
3 Rarely Once a week
4 Once a month Rarely
5 Once a month Rarely
我想最终的结果是具有所有可能的绝对因素,一列的数据帧而列的其余部分是这样的每列/变量计数:
categories one two
Rarely 1 2
Once a month 2 2
Once a week 2 1
我有R上的库没有任何限制所以无论将是最容易在这里(也许plyr
/dplyr
?)。
谢谢。
OP请求data.frame,而这看起来像一个矩阵。可能想要胁迫什么的。 – Frank
@弗兰克同意。 OP可以把它变成任何有用的格式 –
谢谢,我只是在它周围扔一个'as.data.frame'。 :) – firefly2442