# NOT RUN {
# To obtain the entire dataset, run the following code:
library(readr)
library(dplyr)
library(tidyr)
library(lubridate)
library(janitor)
# Get DC characters:
comic_characters_dc <-
"https://github.com/fivethirtyeight/data/raw/master/comic-characters/dc-wikia-data.csv" %>%
read_csv() %>%
clean_names() %>%
mutate(publisher = "DC")
# Get Marvel characters:
comic_characters_marvel <-
"https://github.com/fivethirtyeight/data/raw/master/comic-characters/marvel-wikia-data.csv" %>%
read_csv() %>%
clean_names() %>%
mutate(publisher = "Marvel")
# Merge two dataset and perform further data wrangling:
comic_characters <-
comic_characters_dc %>%
bind_rows(comic_characters_marvel) %>%
separate(first_appearance, c("year2", "month"), ", ", remove = FALSE) %>%
mutate(
# If month was missing, set as January and day as 01:
month = ifelse(is.na(month), "01", month),
day = "01",
# Note some years missing:
date = ymd(paste(year, month, day, sep = "-")),
align = factor(
align,
levels = c("Bad Characters", "Reformed Criminals", "Netural Characters", "Good Characters"),
ordered = TRUE)
) %>%
select(publisher, everything(), -c(year2, day))
# }
Run the code above in your browser using DataLab