

R for Fun Club (RFC)
Do you want to learn R Programming with other lazy coders? This is your group. We also didn’t... View more
How to change values in a dataset using a pipe (%>%).
-
How to change values in a dataset using a pipe (%>%).
This was the question from Duncan’s intermediate class asking about altertives for the below operation
hiv_data <- rio::import("on_ggplot_session_1/hivdata.xlsx")
hiv_data$hiv.gender <- NA # creates an empty column called hiv.gender
hiv_data$hiv.gender[hiv_data$gender==1] <- "Female" # hiv.gender is updated with "Female" if it is 1
hiv_data$hiv.gender[hiv_data$gender==2] <- "Male" # hiv.gender is updated with "Male" if it is 2
Log in to reply.