library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
process_chunk <- function(chunk) {
data_split <- chunk %>%
separate_rows(cast, sep = ", ") %>%
rename(actor = cast)
actor_appearances <- data_split %>%
group_by(actor) %>%
summarise(appearances = n()) %>%
arrange(desc(appearances))
return(actor_appearances)
}
data <- data.frame(
show_id = c(
81145628, 80117401, 70234439, 80058654, 80125979, 80163890, 70304989,
80164077, 80117902, 70304990, 80169755, 70299204, 80182480, 80182483,
80182596
),
type = c(
"Movie", "Movie", "TV Show", "TV Show", "Movie", "TV Show", "Movie",
"Movie", "TV Show", "Movie", "Movie", "Movie", "Movie", "Movie", "Movie"
),
title = c(
"Norm of the North: King Sized Adventure", "Jandino: Whatever it Takes",
"Transformers Prime", "Transformers: Robots in Disguise", "#realityhigh",
"Apaches", "Automata", "Fabrizio Copano: Solo pienso en mi", "Fire Chasers",
"Good People", "Joaquín Reyes: Una y no más", "Kidnapping Mr. Heineken",
"Krish Trish and Baltiboy", "Krish Trish and Baltiboy: Battle of Wits",
"Krish Trish and Baltiboy: Best Friends Forever"
),
director = c(
"Richard Finn, Tim Maltby", "", "", "", "Fernando Lebrija", "", "Gabe Ibáñez",
"Rodrigo Toro, Francisco Schultz", "", "Henrik Ruben Genz", "José Miguel Contreras",
"Daniel Alfredson", "", "Munjal Shroff, Tilak Shetty", "Munjal Shroff, Tilak Shetty"
),
cast = c(
"Alan Marriott, Andrew Toth, Brian Dobson, Cole Howard, Jennifer Cameron, Jonathan Holmes, Lee Tockar, Lisa Durupt, Maya Kay, Michael Dobson",
"Jandino Asporaat",
"Peter Cullen, Sumalee Montano, Frank Welker, Jeffrey Combs, Kevin Michael Richardson, Tania Gunadi, Josh Keaton, Steve Blum, Andy Pessoa, Ernie Hudson, Daran Norris, Will Friedle",
"Will Friedle, Darren Criss, Constance Zimmer, Khary Payton, Mitchell Whitfield, Stuart Allan, Ted McGinley, Peter Cullen",
"Nesta Cooper, Kate Walsh, John Michael Higgins, Keith Powers, Alicia Sanz, Jake Borelli, Kid Ink, Yousef Erakat, Rebekah Graf, Anne Winters, Peter Gilroy, Patrick Davis",
"Alberto Ammann, Eloy Azorín, Verónica Echegui, Lucía Jiménez, Claudia Traisac",
"Antonio Banderas, Dylan McDermott, Melanie Griffith, Birgitte Hjort Sørensen, Robert Forster, Christa Campbell, Tim McInnerny, Andy Nyman, David Ryall",
"Fabrizio Copano",
"",
"James Franco, Kate Hudson, Tom Wilkinson, Omar Sy, Sam Spruell, Anna Friel, Thomas Arnold, Oliver Dimsdale, Diana Hardcastle, Michael Jibson, Diarmaid Murtagh",
"Joaquín Reyes",
"Jim Sturgess, Sam Worthington, Ryan Kwanten, Anthony Hopkins, Mark van Eeuwen, Thomas Cocquerel, Jemima West, David Dencik",
"Damandeep Singh Baggan, Smita Malhotra, Baba Sehgal",
"Damandeep Singh Baggan, Smita Malhotra, Baba Sehgal, Deepak Chachra",
"Damandeep Singh Baggan, Smita Malhotra, Deepak Chachra"
),
country = c(
"United States, India, South Korea, China", "United Kingdom", "United States",
"United States", "United States", "Spain",
"Bulgaria, United States, Spain, Canada", "Chile", "United States",
"United States, United Kingdom, Denmark, Sweden", "", "Netherlands, Belgium, United Kingdom, United States", "",
"", ""
),
date_added = c(
"09-Sep-19", "09-Sep-16", "08-Sep-18", "08-Sep-18", "08-Sep-17", "08-Sep-17",
"08-Sep-17", "08-Sep-17", "08-Sep-17", "08-Sep-17", "08-Sep-17", "08-Sep-17",
"08-Sep-17", "08-Sep-17", "08-Sep-17"
),
release_year = c(
2019, 2016, 2013, 2016, 2017, 2016, 2014, 2017, 2017, 2014, 2017, 2015, 2009, 2013, 2016
),
rating = c(
"TV-PG", "TV-MA", "TV-Y7-FV", "TV-Y7", "TV-14", "TV-MA", "R", "TV-MA", "TV-MA", "R", "TV-MA", "R", "TV-Y7", "TV-Y7", "TV-Y"
),
duration = c(
"90 min", "94 min", "1 Season", "1 Season", "99 min", "1 Season", "110 min", "60 min", "1 Season", "90 min", "78 min", "95 min", "58 min", "62 min", "65 min"
),
listed_in = c(
"Children & Family Movies, Comedies", "Stand-Up Comedy", "Kids' TV", "Kids' TV", "Comedies", "Crime TV Shows, International TV Shows, Spanish-Language TV Shows",
"International Movies, Sci-Fi & Fantasy, Thrillers", "Stand-Up Comedy", "Docuseries, Science & Nature TV",
"Action & Adventure, Thrillers", "Stand-Up Comedy", "Action & Adventure, Dramas, International Movies",
"Children & Family Movies", "Children & Family Movies", "Children & Family Movies"
),
description = c(
"Before planning an awesome wedding for his grandfather, a polar bear king must take back a stolen artifact from an evil archaeologist first.",
"Jandino Asporaat riffs on the challenges of raising kids and serenades the audience with a rousing rendition of \"Sex on Fire\" in his comedy show.",
"With the help of three human allies, the Autobots once again protect Earth from the onslaught of the Decepticons and their leader, Megatron.",
"When a prison ship crash unleashes hundreds of Decepticons on Earth, Bumblebee leads a new Autobot force to protect humankind.",
"When nerdy high schooler Dani finally attracts the interest of her longtime crush, she lands in the cross hairs of his ex, a social media celebrity.",
"A young journalist is forced into a life of crime to save his father and family in this series based on the novel by Miguel Sáez Carral.",
"In a dystopian future, an insurance adjuster for a tech company investigates a robot killed for violating protocol and discovers a global conspiracy.",
"Fabrizio Copano takes audience participation to the next level in this stand-up set while reflecting on sperm banks, family WhatsApp groups and more.",
"As California's 2016 fire season rages, brave backcountry firefighters race to put out the flames, protect homes and save lives in this docuseries.",
"A struggling couple can't believe their luck when they find a stash of money in the apartment of a neighbor who was recently murdered.",
"Comedian and celebrity impersonator Joaquín Reyes decides to be his zesty self for a night of stories about buses, bathroom habits, royalty and more.",
"When beer magnate Alfred \"Freddy\" Heineken is kidnapped in 1983, his abductors make the largest ransom demand in history.",
"A team of minstrels, including a monkey, cat and donkey, narrate folktales from the Indian regions of Rajasthan, Kerala and Punjab.",
"An artisan is cheated of his payment, a lion of his throne and a brother of his inheritance in these three stories of deception and justice.",
"A cat, monkey and donkey team up to narrate folktales about friendship from Northeast India, and the Indian regions of Bihar and Rajasthan."
)
)
final_result <- data.frame()
processed_chunk <- process_chunk(data)
final_result <- bind_rows(final_result, processed_chunk)
top_actors <- final_result %>%
group_by(actor) %>%
summarise(appearances = sum(appearances)) %>%
arrange(desc(appearances)) %>%
head(6)
print(top_actors)
## # A tibble: 6 × 2
## actor appearances
## <chr> <int>
## 1 Damandeep Singh Baggan 3
## 2 Smita Malhotra 3
## 3 Baba Sehgal 2
## 4 Deepak Chachra 2
## 5 Peter Cullen 2
## 6 Will Friedle 2