0

I have a dataframe with a numeric column. How can I substitute all zeros for NAs? I tried

 mtcars <- lapply(mtcars, function(v) {v[v==0] <- NA; v} )

and

 mtcars <- lapply(mtcars, function(v) {v[v==0] <- "NA"; v} )

but then the data are no longer numeric. Does anyone have a suggestion, please? Thank you.

Sylvia Rodriguez
  • 1,203
  • 2
  • 11
  • 30

0 Answers0