Step One: Load required packages by running the code chunk above.

Adding Annotations

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

Importing Data

Goal: Import the my_starwars dataset from the course website.

my_starwars<-read.csv("https://reed-statistics.github.io/math141s21/data/my_starwars.csv")

Creating Categorical Variables

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"
    )
  )

Recoding Levels

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
  ))

Renaming Variables

Goal: Change the name trilogy to first_appearance.

my_starwars <- my_starwars %>% 
  rename(first_appearance = trilogy)

Dealing with Missing Data

Goal: Remove all observations with NA for height

my_starwars <- my_starwars %>% 
  drop_na(height)

Reset Everything

Goal: Undo all changes to the data.

my_starwars<-read.csv("https://reed-statistics.github.io/math141s21/data/my_starwars.csv")