# count the number of games produced per publisher and sort it in decreasing order
publisher = as.data.frame(table(sales$Publisher), stringsAsFactors=FALSE)
colnames(publisher) = c("Publisher", "Frequency")
sort_publisher = publisher[order(publisher$Frequency, decreasing = TRUE),]
rownames(sort_publisher) = c(1:nrow(publisher))
# save the top 5 publishers and group the rest
n = 5
bottom = sort_publisher[(n+1):nrow(publisher),]
other = sum(bottom$Frequency)
publisher_final = sort_publisher[1:n,]
publisher_final[(n+1),] = c("Other", other)
publisher_final
## Publisher Frequency
## 1 Electronic Arts 1351
## 2 Activision 975
## 3 Namco Bandai Games 932
## 4 Ubisoft 921
## 5 Konami Digital Entertainment 832
## 6 Other 11587
The top 5 gaming publishers for popular games purchased by consumers were Electronic Arts (1351 games), Activision (975), Namco Bandai Games (932), Ubisoft (921), and Konami Digital Entertainment (832). Other gaming companies produced 11587 games in total.