library(tidyverse)
# Read data
dinosaurs_raw <- read_csv("dinosaurs.csv")
# Data wrangling
dinosaurs <- dinosaurs_raw |>
select(period, length, name, type) |>
filter(period != "USA") |>
mutate(
period = str_remove(
period, " million years ago"
),
period = str_remove_all(
period, "[0-9]"
),
period = str_remove(period, "-"),
period = str_trim(period),
length = as.numeric(
str_remove(length, "m")
),
name = str_to_title(name),
type = str_to_title(type)
) |>
drop_na() |>
mutate(
period = factor(period, levels = c(
"Late Triassic", "Early Jurassic",
"Mid Jurassic", "Late Jurassic",
"Early Cretaceous",
"Late Cretaceous"
))
)