2

I have a dataset

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

I want to get a count of the 1st column grouped by the column Cluster so used the following code:

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

But getting the following error:

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

Can anybody help out? Thanks in advance!!

user6016731
  • 382
  • 5
  • 18
  • Is `count_` not supposed to be `count` ? Or maybe just `n()` ? – zx8754 Aug 02 '16 at 11:57
  • Also, there is a discrepancy between the code you have pasted and the error you have pasted. `group_by_` is not the same as `group_by` – r.bot Aug 02 '16 at 12:00
  • This is the entire code alongwith the error: 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" – user6016731 Aug 02 '16 at 12:03
  • `count` will not go along with `summarise`. Please check my solution – akrun Aug 02 '16 at 12:04

1 Answers1

2

I guess we need

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

Or

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

Or

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

Or

SFBay_2012 %>%
     group_by(Cluster, company_category_list) %>%
     summarise(n = n())
akrun
  • 874,273
  • 37
  • 540
  • 662