I would like to replace NA values with zeros via mutate_if in dplyr. The syntax below:
set.seed(1)
mtcars[sample(1:dim(mtcars)[1], 5),
       sample(1:dim(mtcars)[2], 5)] <-  NA
require(dplyr)
mtcars %>% 
    mutate_if(is.na,0)
mtcars %>% 
    mutate_if(is.na, funs(. = 0))
Returns error:
Error in
vapply(tbl, p, logical(1), ...): values must be length 1, butFUN(X[[1]])result is length 32
What's the correct syntax for this operation?
 
     
     
     
     
     
    