0
wide
データセットの値に数えてを加算すると、のデータセットをlong
(Person-Period)ファイルに変換する必要がありません。データが溶けずにRカウントが発生する
私のデータは次のようになります。私は何をしたいか
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
私データ。
人周期変換を行わずに列の出現をどのように数えることができますか?
dt = structure(list(alone1 = c("Mentioned", "Mentioned", "Mentioned",
"Mentioned"), alone2 = c("Mentioned", "Mentioned", "Mentioned",
"Mentioned"), alone3 = c("Mentioned", "Mentioned", "Not mentioned",
"Not mentioned"), alone4 = c("Mentioned", "Mentioned", "Not mentioned",
"Not mentioned"), alone5 = c("Mentioned", "Mentioned", "Not mentioned",
"Not mentioned"), alone6 = c("Mentioned", "Mentioned", "Not mentioned",
"Not mentioned"), alone7 = c("Mentioned", "Mentioned", "Not mentioned",
"Not mentioned"), alone8 = c("Mentioned", "Mentioned", "Not mentioned",
"Not mentioned")), .Names = c("alone1", "alone2", "alone3", "alone4",
"alone5", "alone6", "alone7", "alone8"), class = "data.frame", row.names = c(NA, 4L))
おかげで素敵なシンプルなソリューションを必要とします – giacomo