我希望将所有列中的NA值更改为0。
我可以使用mutate()
实现,但无法使用mutate_if()
。
这样做是可行的:
> test <- tibble(Q3.2 = c(1,2, NA, NA, 3),
Q8.2 = c(2, NA, 1, NA, 4))
> test %>% select_("Q3.2", "Q8.2") %>%
mutate(Q3.2 = ifelse(is.na(Q3.2), 0, Q3.2),
Q8.2 = ifelse(is.na(Q8.2), 0, Q8.2))
但是这个不行:
> test %>% select_("Q3.2", "Q8.2") %>%
+ mutate_if(is.na(.), 0, .)
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'p' of mode 'function' was not found