2016-03-23 19 views
0

wide veri kümesinin değerlerini saymaya çalışıyorum, ancak numaralı veri kümesini long (Kişi Dönemi) dosyasına dönüştürmek zorunda kalmadan .R - erime verisi olmadan sayımlar

Benim veri şöyle görünü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 

Ne yapmak istediğini mi

  value n 
1  Mentioned 20 
2 Not mentioned 12 
(bu çıktı istediğim) vermesine bu

library(dplyr) 
library(tidyr) 

dt %>% gather %>% group_by(value) %>% summarise(n = n()) 

olduğunu

Ancak, melt veya gather'u istemiyorum veri.

Bir Kişi Dönemi dönüşümü yapmak zorunda kalmadan sütunların oluşumlarını nasıl basitçe sayabilirim?

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)) 

cevap

2

Bu gerçekten sadece güzel basit bir çözüm table ve unlist sizin data.frame

table(unlist(dt)) 

Mentioned Not mentioned 
     20   12 
+0

sayesinde kullanabilirsiniz sayımları ihtiyaç – giacomo

İlgili konular