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