Reputation: 1
I am currently working on longitudinal data in which I have participants BMI category (normal, overweight, and obese) for three time points, age 7, 9, and 11. I would like to create one new variable that states whether a participant was always normal/overweight/obese, sometimes normal/overweight/obese, or never normal/overweight/obese. Thank you!
Below is the code I ran and R populated back the following error code: "Error in mutate(): In argument: BMICAT_TRAJ = if_else(...)
.
Caused by error in if_else()
:
! argument "false" is missing, with no default"
Data1 <- Data1 %>% mutate(BMICAT_TRAJ = if_else(BMICAT_7 == "Normal" & BMICAT_9 == "Normal" & BMICAT_11 == "Normal", "Always Normal", if_else(BMICAT_7 == "Overweight" & BMICAT_9 == "Overweight" & BMICAT_11 == "Overweight", "Always Overweight", if_else(BMICAT_7 == "Obese" & BMICAT_9 == "Obese" & BMICAT_11 == "Obese", "Always Obese",
if_else(BMICAT_7 == "Normal" & BMICAT_9 != "Normal" | BMICAT_11 != "Normal", "Sometimes Normal",
if_else(BMICAT_7 == "Overweight" & BMICAT_9 != "Overweight" | BMICAT_11 != "Overweight", "Sometimes Overweight",
if_else(BMICAT_7 == "Obese" & BMICAT_9 != "Obese" | BMICAT_11 != "Obese", "Sometimes Obese",
if_else(BMICAT_9 == "Normal" & BMICAT_7 != "Normal" | BMICAT_11 != "Normal", "Sometimes Normal",
if_else(BMICAT_9 == "Overweight" & BMICAT_7 != "Overweight" | BMICAT_11 != "Overweight", "Sometimes Overweight",
if_else(BMICAT_9 == "Obese" & BMICAT_7 != "Obese" | BMICAT_11 != "Obese", "Sometimes Obese",
if_else(BMICAT_11 == "Normal" & BMICAT_9 != "Normal" | BMICAT_7 != "Normal", "Sometimes Normal",
if_else(BMICAT_11 == "Overweight" & BMICAT_9 != "Overweight" | BMICAT_7 != "Overweight", "Sometimes Overweight",
if_else(BMICAT_11 == "Obese" & BMICAT_9 != "Obese" | BMICAT_7 != "Obese", "Sometimes Obese"),
if_else(BMICAT_7 != "Normal" & BMICAT_9 != "Normal" & BMICAT_11 != "Normal", "Never Normal",
if_else(BMICAT_7 != "Overweight" & BMICAT_9 != "Overweight" & BMICAT_11 != "Overweight", "Never Overweight",
if_else(BMICAT_7 != "Obese" & BMICAT_9 != "Obese" & BMICAT_11 != "Obese", "Never Obese", "NA")))))))))))))))
Upvotes: 0
Views: 24