Step One: Load required packages by running the code chunk above.
Goal: Add comments to code
# Any code on a line that begins with a hash will not be run.
# Use this feature to add comments
# Or to save code you might need, but don't want to run
Goal: Import the my_starwars
dataset from the course website.
my_starwars<-read.csv("https://reed-statistics.github.io/math141s21/data/my_starwars.csv")
Goal 1: Create a new categorical variable classifying character heights as small
, medium
or large
.
my_starwars <- my_starwars %>%
mutate(size = case_when(
height < 100 ~ "small",
height >= 100 & height < 200 ~ "medium",
height >= 200 ~ "large"
))
Goal 2: Reduce species variable to two levels: Human
and Non-human
my_starwars <- my_starwars %>%
mutate(
species = if_else(
species=="Human",
"Human",
"Non-human"
)
)
Goal 1: Change the values of force_affiliation
to Jedi
, Sith
, and None
.
my_starwars <- my_starwars %>%
mutate(force_affiliation = recode(force_affiliation,
jedi = "Jedi",
sith = "Sith",
none = "None"
))
Goal 2: Convert force_user
to a quantitative variable.
my_starwars <- my_starwars %>%
mutate(force_user = ifelse(
force_user == "yes",
1,
0
))
Goal: Change the name trilogy
to first_appearance
.
my_starwars <- my_starwars %>%
rename(first_appearance = trilogy)
Goal: Remove all observations with NA
for height
my_starwars <- my_starwars %>%
drop_na(height)
Goal: Undo all changes to the data.
my_starwars<-read.csv("https://reed-statistics.github.io/math141s21/data/my_starwars.csv")