I want to filter by a few criteria but keep the dataframe as is. Is there a filter equivalent that does this?
The overall dataset has 650 entries with 400 columns, and want to edit one subject ID while keeping the rest of the other 650 entries, this is the code I thought of using:
#191-35193895 3 ciders
df %>%
select(subject_id, alc_exp_1:alcohol_exposure_questionnaire_enrolment_complete) %>%
filter (subject_id == "191-25881304" & alc_exp_1b == 999) %>%
mutate(alc_exp_1b = recode(alc_exp_1b, '999' = "3")) %>%
mutate(alc_exp_1c = replace_na(alc_exp_1c, 7))
In detail, I am trying to pick a subject ID and mutate the alc_exp_1b column by replacing 999 with 3, then modify alc_exp_1c by replacing the NA with 7.
This code of course works but over-rides the original dataset.
Please help.