【发布时间】:2020-02-22 02:40:32
【问题描述】:
mtcars1 <- mtcars %>%
mutate(blah = LETTERS[seq(1,26, length.out = nrow(.))],
blah2 = letters[seq(1,26, length.out = nrow(.))])
# sprinkle some random NA values
mtcars1$blah[c(1,3,5,10,11)] <- NA
mtcars1$blah2[c(1,2,5,15,20)] <- NA
mtcars1 %>%
mutate_at(blah:blah2, function(x) {
if_else(is.na(x), 0, x)
})
返回:
Error in check_dot_cols(.vars, .cols) : object 'blah' not found
如何使用 dplyr/tidyverse 方法在多个列中将 NA 替换为 0?
【问题讨论】: