Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gabrielburcea/3ad0d1c48d397f55ff8b59f5d715d679 to your computer and use it in GitHub Desktop.
Save gabrielburcea/3ad0d1c48d397f55ff8b59f5d715d679 to your computer and use it in GitHub Desktop.
Replace NA values with a factor level, use multiple conditions with filter function
df_subset <- df %>%
filter(spell.type == "Emergency" & sex != "Not Specified",
end_datetime >= "2012-09-29" & end_datetime <= "2013-09-29") %>%
mutate(as.Date(end_datetime)) %>%
replace_na(list(patient.class = "Not_Admitted")) %>%
select(pat_code, end_datetime, age_band, sex, patient.class, spell.type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment