I have a dataset with 99 rows with 43 columns. I want to summarise()
the number of times a specific value occurred in each row. I've tried the rowSums()
but keep getting an error message.
head(townRatings)
Municipality 2002 2003 2004 2005 2006 2007 2008
1 Acton Aaa Aaa Aa1 Aa3 Aaa Aa2 Aa1
2 Arlington Baa Aa1 Aa3 Aaa Aa2 Aaa Baa
3 Ashland A1 Aa3 Aa3 Aaa Aa2 Aa1 Aaa
What I want is:
Municipality Aaa Aa1 Aa2 Aa3 A1 Baa
Acton 3 2 1 1 0 0
Arlington 2 1 1 1 0 2
Ashland 2 1 1 2 1 0
I tried to implement the following code:
townRatingsCounts <- townRatings %>% group_by(Municipality) %>%
summarise(Aaa == rowSums("Aaa"), Aa1 == rowSums("Aa1"), Aa2 == rowSums("Aa2"),
Aa3 ==rowSums("Aa3"), A1 == rowSums("A1"), Baa == rowSums("Baa"))