knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, results = "unhide")

# Install packages
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.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) # for importing excel files

Import data

## # A tibble: 1,155 × 13
##    movie_name    release_year director age_difference couple_number actor_1_name
##    <chr>                <dbl> <chr>             <dbl>         <dbl> <chr>       
##  1 Venus                 2006 Roger M…             50             1 Peter O'Too…
##  2 The Quiet Am…         2002 Phillip…             49             1 Michael Cai…
##  3 The Big Lebo…         1998 Joel Co…             45             1 David Huddl…
##  4 Poison Ivy            1992 Katt Sh…             42             1 Tom Skerritt
##  5 Whatever Wor…         2009 Woody A…             40             1 Larry David 
##  6 Entrapment            1999 Jon Ami…             39             1 Sean Connery
##  7 Husbands and…         1992 Woody A…             38             1 Woody Allen 
##  8 Magnolia              1999 Paul Th…             38             1 Jason Robar…
##  9 Indiana Jone…         1989 Steven …             36             1 Sean Connery
## 10 Mr. Peabody …         1948 Irving …             36             1 William Pow…
## # ℹ 1,145 more rows
## # ℹ 7 more variables: actor_2_name <chr>, character_1_gender <chr>,
## #   character_2_gender <chr>, actor_1_birthdate <dttm>,
## #   actor_2_birthdate <dttm>, actor_1_age <dbl>, actor_2_age <dbl>

Apply the following dplyr verbs to your data

Filter rows

## # A tibble: 50 × 13
##    movie_name    release_year director age_difference couple_number actor_1_name
##    <chr>                <dbl> <chr>             <dbl>         <dbl> <chr>       
##  1 Entrapment            1999 Jon Ami…             39             1 Sean Connery
##  2 Magnolia              1999 Paul Th…             38             1 Jason Robar…
##  3 American Bea…         1999 Sam Men…             20             1 Kevin Spacey
##  4 Pushing Tin           1999 Mike Ne…             20             1 Billy Bob T…
##  5 Random Hearts         1999 Sydney …             18             1 Harrison Fo…
##  6 Runaway Bride         1999 Garry M…             18             1 Richard Gere
##  7 The World Is…         1999 Michael…             18             1 Pierce Bros…
##  8 Sleepy Hollow         1999 Tim Bur…             17             1 Johnny Depp 
##  9 Analyze This          1999 Harold …             15             1 Billy Cryst…
## 10 The Sixth Se…         1999 M. Nigh…             13             1 Bruce Willis
## # ℹ 40 more rows
## # ℹ 7 more variables: actor_2_name <chr>, character_1_gender <chr>,
## #   character_2_gender <chr>, actor_1_birthdate <dttm>,
## #   actor_2_birthdate <dttm>, actor_1_age <dbl>, actor_2_age <dbl>

Arrange rows

## # A tibble: 1,155 × 13
##    movie_name    release_year director age_difference couple_number actor_1_name
##    <chr>                <dbl> <chr>             <dbl>         <dbl> <chr>       
##  1 The Bubble            2022 Judd Ap…             21             1 Pedro Pascal
##  2 The Northman          2022 Robert …             20             1 Alexander S…
##  3 Top Gun: Mav…         2022 Joseph …              8             1 Tom Cruise  
##  4 The Lost City         2022 Adam Ne…             16             1 Sandra Bull…
##  5 Everything E…         2022 Dan Kwa…              9             1 Michelle Ye…
##  6 Free Guy              2021 Shawn L…             17             1 Ryan Reynol…
##  7 Red Notice            2021 Rawson …             13             1 Dwayne John…
##  8 Malcolm & Ma…         2021 Sam Lev…             12             1 John David …
##  9 Nightmare Al…         2021 Guiller…             10             1 Bradley Coo…
## 10 In the Heigh…         2021 John M.…             12             1 Daphne Rubi…
## # ℹ 1,145 more rows
## # ℹ 7 more variables: actor_2_name <chr>, character_1_gender <chr>,
## #   character_2_gender <chr>, actor_1_birthdate <dttm>,
## #   actor_2_birthdate <dttm>, actor_1_age <dbl>, actor_2_age <dbl>

Select columns

## # A tibble: 1,155 × 3
##    movie_name                         director             age_difference
##    <chr>                              <chr>                         <dbl>
##  1 Venus                              Roger Michell                    50
##  2 The Quiet American                 Phillip Noyce                    49
##  3 The Big Lebowski                   Joel Coen                        45
##  4 Poison Ivy                         Katt Shea                        42
##  5 Whatever Works                     Woody Allen                      40
##  6 Entrapment                         Jon Amiel                        39
##  7 Husbands and Wives                 Woody Allen                      38
##  8 Magnolia                           Paul Thomas Anderson             38
##  9 Indiana Jones and the Last Crusade Steven Spielberg                 36
## 10 Mr. Peabody and the Mermaid        Irving Pichel                    36
## # ℹ 1,145 more rows

Add columns

Summarize by groups

## # A tibble: 1 × 1
##   ageDifference
##           <dbl>
## 1          10.4