Skip to content
Prev 59128 / 398502 Next

Changing zeros to NAs in a data frame

Laura Holt wrote:

            
Let x be your data.frame. Then use:

is.num <- sapply(x, is.numeric)
x[is.num] <- lapply(x[is.num], function(y) ifelse(y == 0, NA, y))

HTH,

--sundar