I have a datatset like this:
ID A B C
1 1 0 0
1 NA 0 0
2 0 NA NA
2 1 NA 0
reproducible with:
df <- data.frame("ID"=c(rep(1,2),rep(2,2)),"A"=c(1,NA,0,1),"B"=c(rep(0,2),rep(NA,2)),"C"=c(rep(0,2),NA,0))
How can I turn NA into 0 in column A and B without repeting every time:
df$A[is.na(df$A)] <- 0
df$B[is.na(df$B)] <- 0
with a more concise code?