I'm interested in replacing height values (fu_cmi) to NA if two other variables are not equal to 1, indicating height was taken on that visit (fu_cm_takeni & fu_cm_yni) . The i indicates follow up visit number and ranges from 2 to 20. The error message I receive is
' Error in for (. in i) 2:20 : 4 arguments passed to 'for' which requires 3'
cleaned_data_wide_115 <- cleaned_data_wide_115 %>%
for (i in 2:20) {
if (fu_cm_taken[i]!=1 & fu_cm_yn[i]!=1) {
fu_cm[i] = NA
}
else {
fu_cm[i] = fu_cm[i]
}
}