I want to substitute NA by 0 in 20 columns. I found this approach for 2 columns, however I guess it\'s not optimal if the number of columns is 20. Is there any alternative a
Another option:
library(tidyr) v <- c('b', 'c', 'e', 'f') replace_na(df, as.list(setNames(rep(0, length(v)), v)))
Which gives:
# a b c d e f g d.1 #1 1 0 0 2 3 4 7 6 #2 2 g 3 NA 4 5 4 Y #3 3 r 4 4 0 t 5 5