I have a df with 4 columns
Col0 Col1 Col2 COl3 Col4
1 0 NA NA NA
2 0 NA NA NA
3 1 NA NA NA
3 0 NA NA NA
5 1 NA NA NA
I need to fill Col2, Col3 and Col4 based on the values of Col1 So if Col1 is 0, Col2,Col3 and Col4 should be filled with 0 If Col1 is 1, Col2,Col3 and Col4 should be filled with the value of Col0 Else Col2,Col3 and Col4 should be filled with the value of average of Col0 and Col1.
df$Col2[df$Col1==0]<-0
affects only 1 column.
Expected output:
Col0 Col1 Col2 COl3 Col4
1 0 0 0 0
2 0 0 0 0
3 1 3 3 3
3 0 0 0 0
5 1 3 3 3