2016-08-02 118 views
1

我有一个数据集Dplyr总结列

company_category_list Cluster 
Biotechnology   1 
Software    2 
Biotechnology|Search 1 
Biotechnology   1 
Biotechnology   1 
Enterprise Software 3 
Software    2 

我想由列集群分组的第一列的数量,使得用下面的代码:

library(dplyr) 
CountSummary <-SFBay_2012 %>% 
group_by(Cluster) %>% 
summarise(company_category_list_Count = count_(company_category_list)) 

但是,得到以下错误:

Error: no applicable method for 'group_by_' applied to an object of class "factor" 

任何人都可以帮忙吗? 在此先感谢!

+0

是'count_'不应该是'合作没有'?或者只是'n()'? – zx8754

+0

此外,您粘贴的代码与您粘贴的错误之间存在差异。 “group_by_”与“group_by”不一样 –

+0

这是整个代码以及错误:CountSummary <-SFBay_2012%>% + group_by(集群)%>% +汇总(company_category_list_Count = count(company_category_list)) 错误:没有将“group_by_”应用于类“factor” – user6016731

回答

0

我想我们需要

SFBay_2012 %>% 
     group_by(Cluster) %>% 
     count(company_category_list) 
# Cluster company_category_list  n 
# <int>     <chr> <int> 
#1  1   Biotechnology  3 
#2  1 Biotechnology|Search  1 
#3  2    Software  2 
#4  3 Enterprise Software  1 

或者

SFBay_2012 %>% 
     count(Cluster, company_category_list) 
# Cluster company_category_list  n 
# <int>     <chr> <int> 
#1  1   Biotechnology  3 
#2  1 Biotechnology|Search  1 
#3  2    Software  2 
#4  3 Enterprise Software  1 

或者

SFBay_2012 %>% 
     group_by(Cluster, company_category_list) %>% 
     tally() 
# Cluster company_category_list  n 
#  <int>     <chr> <int> 
#1  1   Biotechnology  3 
#2  1 Biotechnology|Search  1 
#3  2    Software  2 
#4  3 Enterprise Software  1 

或者