Opposite to Set NA to 0 in R, I have a data.frame data
with columns A and B (and other) in which NAs were replaced by 0 by
rowSums(data[,c("A", "B")], na.rm=TRUE)
.
I need to re-replace all 0 values by NA
. As I am working with a data.frame containing not only numeric values, convert all zeros of a matrix in R to NA doesn't work for me (converting into a matrix doesn't seem promising here).
I tried
data["A" == 0] <- NA
and data["B" == 0] <- NA
- however, it doesn't do anything (the data.frame seems to stay unchanged)