I am trying to write a for loop and if statement that correct a column. This is the code I tried to do. If time is not NA and CA = 0 then CA = 1. If time is NA and CA = 0 then CA = 0. Else CA = 2
Data dfz:
| Time | CA | FO | 
|---|---|---|
| 200 | 0 | 0 | 
| 1000 | 0 | 0 | 
| 500 | 0 | 0 | 
| 800 | 0 | 0 | 
| 1200 | 0 | 0 | 
| 1300 | 0 | 0 | 
| 1800 | 0 | 0 | 
| 1500 | 0 | 0 | 
| NA | 0 | 0 | 
| NA | 0 | 0 | 
| NA | 0 | 0 | 
This is the code I have tried but keep getting all 2 or 0:
for (x in dfz$Time) {
  for(y in dfz$CA){
    if(!(is.na(x)) & y == 0){
      dfz$CA = 1
      }else if ((is.na(x)) & y == 0){
        dfz$CA = 0
        }else{
          dfz$CA = dfz$CA
        }
    }
}
 
    