There are multiple ways with which you can do that, below are some ways;
Using dplyr
# Call dplyr package
library(dplyr)
# Create dataset
data <-
data.frame(
type = c("Action", "Thriller", "Drama", "Drama", "Romance", "Romance",
"Comedy", "Comedy", "Comedy", "Drama", "Drama", "Drama",
"Action", "Action", "Action", "Action", "Thriller")
)
data %>%
group_by(type) %>% # To count per column called type (can be dropped if there is only type column in the dataframe)
count() # Count
# A tibble: 5 x 2
# Groups: type [5]
# type n
# <fct> <int>
# Action 5
# Comedy 3
# Drama 5
# Romance 2
# Thriller 2
Without need for package
table(data)
# data
# Action Comedy Drama Romance Thriller
# 5 3 5 2 2
Using janitor to get percentage as well
janitor::tabyl(data$type)
# data$type n percent
# Action 5 0.2941176
# Comedy 3 0.1764706
# Drama 5 0.2941176
# Romance 2 0.1176471
# Thriller 2 0.1176471