我正在尝试简单地计算className
数据集的值,但没有必须将数据集转换为wide
(人 - 期)文件。
我的数据如下:
long
我想做的是这个
alone1 alone2 alone3 alone4 alone5 alone6 alone7 alone8
1 Mentioned Mentioned Mentioned Mentioned Mentioned Mentioned Mentioned Mentioned
2 Mentioned Mentioned Mentioned Mentioned Mentioned Mentioned Mentioned Mentioned
3 Mentioned Mentioned Not mentioned Not mentioned Not mentioned Not mentioned Not mentioned Not mentioned
4 Mentioned Mentioned Not mentioned Not mentioned Not mentioned Not mentioned Not mentioned Not mentioned
这给了我(这是我想要的输出)
library(dplyr)
library(tidyr)
dt %>% gather %>% group_by(value) %>% summarise(n = n())
但是,我不想 value n
1 Mentioned 20
2 Not mentioned 12
或melt
我的数据。
任何想法我怎么能简单地计算列的出现而不必进行人员周期转换?
gather
答案 0 :(得分:2)
你真的需要你可以使用table
和unlist
data.frame
table(unlist(dt))
Mentioned Not mentioned
20 12