data.frame and table in R

Viewed 28

i have a list of movies and List of workers like directors and players for each film. i need to show a list of the movies and the number of workers to each movie with the help of table and dataframe.

What the result should look like

but when i make the table to director and onther table to workers and want to make dataframe from them it gives me an error because there is a different amount of lines because they don't add to the table movies without workers to the workers table or and the same with director.

any help please? thank you,

numDirectors <- table(imdb.players[imdb.players$role == "Director",]$id)
numWriter <- table(imdb.players[imdb.players$role == "Writer",]$id)
               
numall.df <- data.frame(numDirectors,numWriter)
1 Answers

We may use in% instead of == to get multiple 'role' elements and apply the table once on the 'role' and 'id' columns

as.data.frame(table(subset(imbd.players, role %in% c("Director", "Writer"), 
      select = c(role, id))))
Related