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
  • 963
  • 1
  • 7
  • 16

0 Answers0