A five columns table ("id", "othermood_v","rass_v", "gcs_v" and "cam_v") with around 52000 rows. There are three values in the last column ("cam_v"):0,1,2 as a class label. The "cam_v" column now has value as 1, 2 and NA. I would like to replace the NA value with either 0 or 1 based the other three columns "othermood_v", "rass_v" and "gcs_v". So if any of these three columns in the same row has a value like 1, then cam_v would be labeled as 1, otherwise 0. I tried to loop through data with a condition like
if df$othermood_v>0|df$rass_v>0|df$gcs_v >0, then df$cam_v=1 else
0, rm NA = True
or
if (df$othermood_v+df$rass_v+df$gcs_v) >0, then cam_v=1 else 0
But I don't know how to get it to work. Any suggestions? BTW, the id is unique now. Thanks.
id othermood_v rass_v gcs_v cam_v
100078 0 0 0 NA
100079 0 0 0 NA
100081 0 0 0 NA
100085 1 1 0 NA
100087 1 1 0 NA
100088 1 0 0 NA
100091 1 1 1 2
100094 0 1 0 NA
100095 1 0 0 NA
100096 0 0 0 NA
100098 1 1 1 2
100099 0 1 0 NA
100102 1 0 0 NA
100103 1 0 0 NA
100104 1 1 0 2
100106 0 0 0 NA
100108 1 0 0 NA
100109 1 0 0 NA
100112 1 0 0 NA
100113 1 1 1 1
100114 1 0 0 NA
100116 1 0 0 NA
100117 1 0 0 NA
100118 0 1 0 NA