Skip to content

Instantly share code, notes, and snippets.

@MonkmanMH
Last active October 18, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MonkmanMH/a78abfce7590fb2c2ba4a617fd8596ef to your computer and use it in GitHub Desktop.
Save MonkmanMH/a78abfce7590fb2c2ba4a617fd8596ef to your computer and use it in GitHub Desktop.
quick
# quick example of mutate (in the dplyr R package) to create a dummy variable
# packages (from the tidyverse)
library(tibble)
library(dplyr)
# a little tibble with an ID number and a gender variable (5 Female, 3 Male, 2 Not Stated)
mydata <- tibble(id = 1:10, gender = c("F", "F", "F", "F", "F",
"M", "M", "M",
"NS", "NS"))
# create dummy variable for modeling, where Female = 1 and all others = 0
mydata %>%
mutate(dummy = ifelse(gender == "F", 1, 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment