Lab report #3 - instructions

Follow the instructions posted at https://ds202-at-isu.github.io/labs.html for the lab assignment. The work is meant to be finished during the lab time, but you have time until Monday evening to polish things.

Include your answers in this document (Rmd file). Make sure that it knits properly (into the md file). Upload both the Rmd and the md file to your repository.

All submissions to the github repo will be automatically uploaded for grading once the due date is passed. Submit a link to your repository on Canvas (only one submission per team) to signal to the instructors that you are done with your submission.

Lab 3: Avenger’s Peril

As a team

Extract from the data below two data sets in long form deaths and returns

av <- read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/avengers/avengers.csv", stringsAsFactors = FALSE)
head(av)
##                                                       URL
## 1           http://marvel.wikia.com/Henry_Pym_(Earth-616)
## 2      http://marvel.wikia.com/Janet_van_Dyne_(Earth-616)
## 3       http://marvel.wikia.com/Anthony_Stark_(Earth-616)
## 4 http://marvel.wikia.com/Robert_Bruce_Banner_(Earth-616)
## 5        http://marvel.wikia.com/Thor_Odinson_(Earth-616)
## 6       http://marvel.wikia.com/Richard_Jones_(Earth-616)
##                    Name.Alias Appearances Current. Gender Probationary.Introl
## 1   Henry Jonathan "Hank" Pym        1269      YES   MALE                    
## 2              Janet van Dyne        1165      YES FEMALE                    
## 3 Anthony Edward "Tony" Stark        3068      YES   MALE                    
## 4         Robert Bruce Banner        2089      YES   MALE                    
## 5                Thor Odinson        2402      YES   MALE                    
## 6      Richard Milhouse Jones         612      YES   MALE                    
##   Full.Reserve.Avengers.Intro Year Years.since.joining Honorary Death1 Return1
## 1                      Sep-63 1963                  52     Full    YES      NO
## 2                      Sep-63 1963                  52     Full    YES     YES
## 3                      Sep-63 1963                  52     Full    YES     YES
## 4                      Sep-63 1963                  52     Full    YES     YES
## 5                      Sep-63 1963                  52     Full    YES     YES
## 6                      Sep-63 1963                  52 Honorary     NO        
##   Death2 Return2 Death3 Return3 Death4 Return4 Death5 Return5
## 1                                                            
## 2                                                            
## 3                                                            
## 4                                                            
## 5    YES      NO                                             
## 6                                                            
##                                                                                                                                                                              Notes
## 1                                                                                                                Merged with Ultron in Rage of Ultron Vol. 1. A funeral was held. 
## 2                                                                                                  Dies in Secret Invasion V1:I8. Actually was sent tto Microverse later recovered
## 3 Death: "Later while under the influence of Immortus Stark committed a number of horrible acts and was killed.'  This set up young Tony. Franklin Richards later brought him back
## 4                                                                               Dies in Ghosts of the Future arc. However "he had actually used a hidden Pantheon base to survive"
## 5                                                      Dies in Fear Itself brought back because that's kind of the whole point. Second death in Time Runs Out has not yet returned
## 6                                                                                                                                                                             <NA>

Get the data into a format where the five columns for Death[1-5] are replaced by two columns: Time, and Death. Time should be a number between 1 and 5 (look into the function parse_number); Death is a categorical variables with values “yes”, “no” and ““. Call the resulting data set deaths.

library(tidyr)
library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'

## The following objects are masked from 'package:stats':
## 
##     filter, lag

## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
deaths <- av |>
  pivot_longer(cols = c("Death1", "Death2", "Death3", "Death4", "Death5"),
               names_to = "Time",
               values_to = "Death") |>
  filter(Death != "")

deaths$Time <- parse_number(deaths$Time)

head(deaths)
## # A tibble: 6 × 18
##   URL                 Name.Alias Appearances Current. Gender Probationary.Introl
##   <chr>               <chr>            <int> <chr>    <chr>  <chr>              
## 1 http://marvel.wiki… "Henry Jo…        1269 YES      MALE   ""                 
## 2 http://marvel.wiki… "Janet va…        1165 YES      FEMALE ""                 
## 3 http://marvel.wiki… "Anthony …        3068 YES      MALE   ""                 
## 4 http://marvel.wiki… "Robert B…        2089 YES      MALE   ""                 
## 5 http://marvel.wiki… "Thor Odi…        2402 YES      MALE   ""                 
## 6 http://marvel.wiki… "Thor Odi…        2402 YES      MALE   ""                 
## # ℹ 12 more variables: Full.Reserve.Avengers.Intro <chr>, Year <int>,
## #   Years.since.joining <int>, Honorary <chr>, Return1 <chr>, Return2 <chr>,
## #   Return3 <chr>, Return4 <chr>, Return5 <chr>, Notes <chr>, Time <dbl>,
## #   Death <chr>

Similarly, deal with the returns of characters.

returns <- av |>
  pivot_longer(cols = c("Return1", "Return2", "Return3", "Return4", "Return5"),
               names_to = "Time",
               values_to = "Return") |>
  filter(Return != "")

returns$Time <- parse_number(returns$Time) 

head(returns)
## # A tibble: 6 × 18
##   URL                 Name.Alias Appearances Current. Gender Probationary.Introl
##   <chr>               <chr>            <int> <chr>    <chr>  <chr>              
## 1 http://marvel.wiki… "Henry Jo…        1269 YES      MALE   ""                 
## 2 http://marvel.wiki… "Janet va…        1165 YES      FEMALE ""                 
## 3 http://marvel.wiki… "Anthony …        3068 YES      MALE   ""                 
## 4 http://marvel.wiki… "Robert B…        2089 YES      MALE   ""                 
## 5 http://marvel.wiki… "Thor Odi…        2402 YES      MALE   ""                 
## 6 http://marvel.wiki… "Thor Odi…        2402 YES      MALE   ""                 
## # ℹ 12 more variables: Full.Reserve.Avengers.Intro <chr>, Year <int>,
## #   Years.since.joining <int>, Honorary <chr>, Death1 <chr>, Death2 <chr>,
## #   Death3 <chr>, Death4 <chr>, Death5 <chr>, Notes <chr>, Time <dbl>,
## #   Return <chr>

Based on these datasets calculate the average number of deaths an Avenger suffers.

Individually

For each team member, copy this part of the report.

Each team member picks one of the statements in the FiveThirtyEight analysis and fact checks it based on the data. Use dplyr functionality whenever possible.

FiveThirtyEight Statement

“Out of 173 listed Avengers, how many have died at least once after joining the team?”

# Count Avengers who died at least once
dead_avengers <- deaths |>
  filter(Death == "YES") |>
  distinct(Name.Alias)

num_dead <- nrow(dead_avengers)

# Total number of Avengers
total_avengers <- nrow(av)

# Percentage
percent_dead <- (num_dead / total_avengers) * 100

num_dead
## [1] 64
total_avengers
## [1] 173
percent_dead
## [1] 36.99422

Include your answer

After filtering the deaths data set for Avengers whose death status was marked “YES” and removing duplicates, there are 64 unique Avengers who died at least once. Since the data set contains 173 total Avengers, approximately 36.9% of Avengers experienced at least one death, which matches the article’s claim that about 40% of Avengers have died (or at least, it’s close enough).

Upload your changes to the repository. Discuss and refine answers as a team.