Skip to content

Instantly share code, notes, and snippets.

@MonkmanMH

MonkmanMH/dummy_var.R

Last active Oct 18, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.