0

How can i calculate and print the result in new column?

Case:

Horror
Horror
Horror
Horror
Adventure
Action
Action
Horror

Output:

|Category | Total |
| Horror | 5 |
| Action | 2 |
| Adventure | 1 |

Tommy
  • 11
  • 3

1 Answers1

0

We can use table

as.data.frame(table(df1$Category))

Or

library(data.table)
setDT(df1)[, list(Total=.N), Category]

Or

library(dplyr)
df1 %>%
   group_by(Category) %>%
   summmarise(Total=n())
akrun
  • 874,273
  • 37
  • 540
  • 662