R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(readxl)

if (!require("pacman")) install.packages("pacman")
## Loading required package: pacman
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.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ 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
library(readxl)

readxl::read_excel("./netflix.xlsx")
## # A tibble: 6,234 × 12
##     show_id type    title  director cast  country date_added release_year rating
##       <dbl> <chr>   <chr>  <chr>    <chr> <chr>   <chr>             <dbl> <chr> 
##  1 81145628 Movie   Norm … Richard… Alan… United… September…         2019 TV-PG 
##  2 80117401 Movie   Jandi… <NA>     Jand… United… September…         2016 TV-MA 
##  3 70234439 TV Show Trans… <NA>     Pete… United… September…         2013 TV-Y7…
##  4 80058654 TV Show Trans… <NA>     Will… United… September…         2016 TV-Y7 
##  5 80125979 Movie   #real… Fernand… Nest… United… September…         2017 TV-14 
##  6 80163890 TV Show Apach… <NA>     Albe… Spain   September…         2016 TV-MA 
##  7 70304989 Movie   Autom… Gabe Ib… Anto… Bulgar… September…         2014 R     
##  8 80164077 Movie   Fabri… Rodrigo… Fabr… Chile   September…         2017 TV-MA 
##  9 80117902 TV Show Fire … <NA>     <NA>  United… September…         2017 TV-MA 
## 10 70304990 Movie   Good … Henrik … Jame… United… September…         2014 R     
## # ℹ 6,224 more rows
## # ℹ 3 more variables: duration <chr>, listed_in <chr>, description <chr>
path1 = "./netflix.xlsx"

netflix_tbl <- read_excel(path1)


netflix_tbl
## # A tibble: 6,234 × 12
##     show_id type    title  director cast  country date_added release_year rating
##       <dbl> <chr>   <chr>  <chr>    <chr> <chr>   <chr>             <dbl> <chr> 
##  1 81145628 Movie   Norm … Richard… Alan… United… September…         2019 TV-PG 
##  2 80117401 Movie   Jandi… <NA>     Jand… United… September…         2016 TV-MA 
##  3 70234439 TV Show Trans… <NA>     Pete… United… September…         2013 TV-Y7…
##  4 80058654 TV Show Trans… <NA>     Will… United… September…         2016 TV-Y7 
##  5 80125979 Movie   #real… Fernand… Nest… United… September…         2017 TV-14 
##  6 80163890 TV Show Apach… <NA>     Albe… Spain   September…         2016 TV-MA 
##  7 70304989 Movie   Autom… Gabe Ib… Anto… Bulgar… September…         2014 R     
##  8 80164077 Movie   Fabri… Rodrigo… Fabr… Chile   September…         2017 TV-MA 
##  9 80117902 TV Show Fire … <NA>     <NA>  United… September…         2017 TV-MA 
## 10 70304990 Movie   Good … Henrik … Jame… United… September…         2014 R     
## # ℹ 6,224 more rows
## # ℹ 3 more variables: duration <chr>, listed_in <chr>, description <chr>
str(netflix_tbl)
## tibble [6,234 × 12] (S3: tbl_df/tbl/data.frame)
##  $ show_id     : num [1:6234] 81145628 80117401 70234439 80058654 80125979 ...
##  $ type        : chr [1:6234] "Movie" "Movie" "TV Show" "TV Show" ...
##  $ title       : chr [1:6234] "Norm of the North: King Sized Adventure" "Jandino: Whatever it Takes" "Transformers Prime" "Transformers: Robots in Disguise" ...
##  $ director    : chr [1:6234] "Richard Finn, Tim Maltby" NA NA NA ...
##  $ cast        : chr [1:6234] "Alan Marriott, Andrew Toth, Brian Dobson, Cole Howard, Jennifer Cameron, Jonathan Holmes, Lee Tockar, Lisa Duru"| __truncated__ "Jandino Asporaat" "Peter Cullen, Sumalee Montano, Frank Welker, Jeffrey Combs, Kevin Michael Richardson, Tania Gunadi, Josh Keaton"| __truncated__ "Will Friedle, Darren Criss, Constance Zimmer, Khary Payton, Mitchell Whitfield, Stuart Allan, Ted McGinley, Peter Cullen" ...
##  $ country     : chr [1:6234] "United States, India, South Korea, China" "United Kingdom" "United States" "United States" ...
##  $ date_added  : chr [1:6234] "September 9, 2019" "September 9, 2016" "September 8, 2018" "September 8, 2018" ...
##  $ release_year: num [1:6234] 2019 2016 2013 2016 2017 ...
##  $ rating      : chr [1:6234] "TV-PG" "TV-MA" "TV-Y7-FV" "TV-Y7" ...
##  $ duration    : chr [1:6234] "90 min" "94 min" "1 Season" "1 Season" ...
##  $ listed_in   : chr [1:6234] "Children & Family Movies, Comedies" "Stand-Up Comedy" "Kids' TV" "Kids' TV" ...
##  $ description : chr [1:6234] "Before planning an awesome wedding for his grandfather, a polar bear king must take back a stolen artifact from"| __truncated__ "Jandino Asporaat riffs on the challenges of raising kids and serenades the audience with a rousing rendition of"| __truncated__ "With the help of three human allies, the Autobots once again protect Earth from the onslaught of the Decepticon"| __truncated__ "When a prison ship crash unleashes hundreds of Decepticons on Earth, Bumblebee leads a new Autobot force to protect humankind." ...
glimpse(netflix_tbl)
## Rows: 6,234
## Columns: 12
## $ show_id      <dbl> 81145628, 80117401, 70234439, 80058654, 80125979, 8016389…
## $ type         <chr> "Movie", "Movie", "TV Show", "TV Show", "Movie", "TV Show…
## $ title        <chr> "Norm of the North: King Sized Adventure", "Jandino: What…
## $ director     <chr> "Richard Finn, Tim Maltby", NA, NA, NA, "Fernando Lebrija…
## $ cast         <chr> "Alan Marriott, Andrew Toth, Brian Dobson, Cole Howard, J…
## $ country      <chr> "United States, India, South Korea, China", "United Kingd…
## $ date_added   <chr> "September 9, 2019", "September 9, 2016", "September 8, 2…
## $ release_year <dbl> 2019, 2016, 2013, 2016, 2017, 2016, 2014, 2017, 2017, 201…
## $ rating       <chr> "TV-PG", "TV-MA", "TV-Y7-FV", "TV-Y7", "TV-14", "TV-MA", …
## $ duration     <chr> "90 min", "94 min", "1 Season", "1 Season", "99 min", "1 …
## $ listed_in    <chr> "Children & Family Movies, Comedies", "Stand-Up Comedy", …
## $ description  <chr> "Before planning an awesome wedding for his grandfather, …
netflix_tbl %>% 
  select(starts_with("show_id"))
## # A tibble: 6,234 × 1
##     show_id
##       <dbl>
##  1 81145628
##  2 80117401
##  3 70234439
##  4 80058654
##  5 80125979
##  6 80163890
##  7 70304989
##  8 80164077
##  9 80117902
## 10 70304990
## # ℹ 6,224 more rows
netflix_tbl %>% 
  select(title:cast, listed_in)
## # A tibble: 6,234 × 4
##    title                                   director              cast  listed_in
##    <chr>                                   <chr>                 <chr> <chr>    
##  1 Norm of the North: King Sized Adventure Richard Finn, Tim Ma… Alan… Children…
##  2 Jandino: Whatever it Takes              <NA>                  Jand… Stand-Up…
##  3 Transformers Prime                      <NA>                  Pete… Kids' TV 
##  4 Transformers: Robots in Disguise        <NA>                  Will… Kids' TV 
##  5 #realityhigh                            Fernando Lebrija      Nest… Comedies 
##  6 Apaches                                 <NA>                  Albe… Crime TV…
##  7 Automata                                Gabe Ibáñez           Anto… Internat…
##  8 Fabrizio Copano: Solo pienso en mi      Rodrigo Toro, Franci… Fabr… Stand-Up…
##  9 Fire Chasers                            <NA>                  <NA>  Docuseri…
## 10 Good People                             Henrik Ruben Genz     Jame… Action &…
## # ℹ 6,224 more rows
netflix_tbl %>% 
  pull(show_id) %>% 
  mean()
## [1] 76703679
netflix_tbl %>% 
  select_if(is.numeric)
## # A tibble: 6,234 × 2
##     show_id release_year
##       <dbl>        <dbl>
##  1 81145628         2019
##  2 80117401         2016
##  3 70234439         2013
##  4 80058654         2016
##  5 80125979         2017
##  6 80163890         2016
##  7 70304989         2014
##  8 80164077         2017
##  9 80117902         2017
## 10 70304990         2014
## # ℹ 6,224 more rows
netflix_tbl %>% 
  select(title, cast) %>% 
  arrange(desc(cast))
## # A tibble: 6,234 × 2
##    title                cast                                                    
##    <chr>                <chr>                                                   
##  1 Winter Sun           Şükrü Özyıldız, Aslı Enver, Şenay Gürler, Başak Parlak,…
##  2 Intersection         İbrahim Çelikkol, Belçim Bilgin, Alican Yücesoy, Teoman…
##  3 Küçük Esnaf          İbrahim Büyükak, Zeynep Koçak, Gupse Özay, Cengiz Bozku…
##  4 The Tree of Blood    Úrsula Corberó, Álvaro Cervantes, Najwa Nimri, Patricia…
##  5 La casa de papel     Úrsula Corberó, Itziar Ituño, Álvaro Morte, Paco Tous, …
##  6 Babam ve Oğlum       Çetin Tekindor, Fikret Kuşkan, Hümeyra, Ege Tanman, Şer…
##  7 The Protector        Çağatay Ulusoy, Ayça Ayşin Turan, Hazar Ergüçlü, Okan Y…
##  8 The Apostate         Álvaro Ogalla, Marta Larralde, Bárbara Lennie, Vicky Pe…
##  9 The Next Skin        Àlex Monner, Emma Suárez, Sergi López, Bruno Todeschini…
## 10 Westerplatte Resists Zygmunt Hübner, Arkadiusz Bazak, Tadeusz Schmidt, Józef…
## # ℹ 6,224 more rows
netflix_tbl %>% 
  arrange(cast) %>% 
  slice(1:5) %>% 
  View()

netflix_tbl %>% 
  distinct(cast, title) %>% 
  View()


netflix_tbl %>% 
  rename( actor = cast) %>% 
  rename( tv_show = title) %>% 
  View()

netflix_tbl %>% 
  drop_na()
## # A tibble: 3,774 × 12
##     show_id type  title    director cast  country date_added release_year rating
##       <dbl> <chr> <chr>    <chr>    <chr> <chr>   <chr>             <dbl> <chr> 
##  1 81145628 Movie Norm of… Richard… Alan… United… September…         2019 TV-PG 
##  2 80125979 Movie #realit… Fernand… Nest… United… September…         2017 TV-14 
##  3 70304989 Movie Automata Gabe Ib… Anto… Bulgar… September…         2014 R     
##  4 80164077 Movie Fabrizi… Rodrigo… Fabr… Chile   September…         2017 TV-MA 
##  5 70304990 Movie Good Pe… Henrik … Jame… United… September…         2014 R     
##  6 70299204 Movie Kidnapp… Daniel … Jim … Nether… September…         2015 R     
##  7 80057969 Movie Love     Gaspar … Karl… France… September…         2015 NR    
##  8 80060297 Movie Manhatt… Tom O'B… Tom … United… September…         2014 TV-14 
##  9 80046728 Movie Moonwal… Antoine… Ron … France… September…         2015 R     
## 10 70304988 Movie Stonehe… Brad An… Kate… United… September…         2014 PG-13 
## # ℹ 3,764 more rows
## # ℹ 3 more variables: duration <chr>, listed_in <chr>, description <chr>
netflix_tbl %>% 
  replace_na(list(rebounds = 0)) %>% str()
## tibble [6,234 × 12] (S3: tbl_df/tbl/data.frame)
##  $ show_id     : num [1:6234] 81145628 80117401 70234439 80058654 80125979 ...
##  $ type        : chr [1:6234] "Movie" "Movie" "TV Show" "TV Show" ...
##  $ title       : chr [1:6234] "Norm of the North: King Sized Adventure" "Jandino: Whatever it Takes" "Transformers Prime" "Transformers: Robots in Disguise" ...
##  $ director    : chr [1:6234] "Richard Finn, Tim Maltby" NA NA NA ...
##  $ cast        : chr [1:6234] "Alan Marriott, Andrew Toth, Brian Dobson, Cole Howard, Jennifer Cameron, Jonathan Holmes, Lee Tockar, Lisa Duru"| __truncated__ "Jandino Asporaat" "Peter Cullen, Sumalee Montano, Frank Welker, Jeffrey Combs, Kevin Michael Richardson, Tania Gunadi, Josh Keaton"| __truncated__ "Will Friedle, Darren Criss, Constance Zimmer, Khary Payton, Mitchell Whitfield, Stuart Allan, Ted McGinley, Peter Cullen" ...
##  $ country     : chr [1:6234] "United States, India, South Korea, China" "United Kingdom" "United States" "United States" ...
##  $ date_added  : chr [1:6234] "September 9, 2019" "September 9, 2016" "September 8, 2018" "September 8, 2018" ...
##  $ release_year: num [1:6234] 2019 2016 2013 2016 2017 ...
##  $ rating      : chr [1:6234] "TV-PG" "TV-MA" "TV-Y7-FV" "TV-Y7" ...
##  $ duration    : chr [1:6234] "90 min" "94 min" "1 Season" "1 Season" ...
##  $ listed_in   : chr [1:6234] "Children & Family Movies, Comedies" "Stand-Up Comedy" "Kids' TV" "Kids' TV" ...
##  $ description : chr [1:6234] "Before planning an awesome wedding for his grandfather, a polar bear king must take back a stolen artifact from"| __truncated__ "Jandino Asporaat riffs on the challenges of raising kids and serenades the audience with a rousing rendition of"| __truncated__ "With the help of three human allies, the Autobots once again protect Earth from the onslaught of the Decepticon"| __truncated__ "When a prison ship crash unleashes hundreds of Decepticons on Earth, Bumblebee leads a new Autobot force to protect humankind." ...

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.