library(tidyverse)
# Read data
<- read_csv("dinosaurs.csv")
dinosaurs_raw
# Data wrangling
<- dinosaurs_raw |>
dinosaurs select(period, length, name, type) |>
filter(period != "USA") |>
mutate(
period = str_remove(
" million years ago"
period,
),period = str_remove_all(
"[0-9]"
period,
),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"
)) )