Skip to content

Instantly share code, notes, and snippets.

@gabrielburcea
Last active August 16, 2018 09:26
Show Gist options
  • Save gabrielburcea/daa4f5d23589ea25f551076894fb551f to your computer and use it in GitHub Desktop.
Save gabrielburcea/daa4f5d23589ea25f551076894fb551f to your computer and use it in GitHub Desktop.
Creating a new variable out of two - case_when ; group_indices - tidyerse
# Creating a new variable out of two
data_indices <- df_subs %>%
mutate(sex_patient_class = case_when(
sex == "Female" & patient.class == "Not_Admitted" ~ "female_not_admitted",
sex == "Female" & patient.class == "ORDINARY ADMISSION" ~ "female_admitted",
sex == "Male" & patient.class == "Not_Admitted" ~ "male_not_admitted",
sex == "Male" & patient.class == "ORDINARY ADMISSION" ~ "male_admitted"
))
# Generate a unique id for each group
df_group_indices <- data_indices %>%
mutate(group_indices = group_indices(., patient.class, sex))
# sex_patient_class using unite - yet do not get any id with this function
df_subs_indices <- df_subs %>%
unite(sex_patient_class, sex, patient.class, sep = "_")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment