library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(tidyr)
df <- data.frame(stringsAsFactors = FALSE,
X1 = c(NA,NA,1004,NA),
Y1= c(NA,NA,100,100),
X2 = c(NA,50,100,100),
Y2 = c(100,100,200,300)
)
tab.na<-df%>%
mutate_all(.,funs(replace_na(., 0))) %>%
mutate_if(is.numeric,funs(replace_na(., 0)))
You can see that there are no error but the result is not OK because
I don't want a change to line 3
I want zeros everywhere else.