我想对第2列到第4列的值进行变异
NA
mutate across
没有成功。
library(tidyverse)
df <- tibble(year = 2020, a = 1, b = 2, c = 3)
df %>% mutate(across(c(2:4), is.na))
#> # A tibble: 1 x 4
#> year a b c
#> <dbl> <lgl> <lgl> <lgl>
#> 1 2020 FALSE FALSE FALSE
# But this gives an error because NA is not a function
# df %>% mutate(across(c(2:4), NA))
Created on 2021-10-30 by the reprex package (v2.0.1)