这是我的数据的 MWE,我想从包含“Med”的所有列中删除字符串“NaN”
df= data.frame(id= rep(1:5, each=1),
Med1 = c("GN", "GN", "Ca", "Ca", "DM"),
Med2 = c("DM", "NaN", "Mob", "NaN", "NaN"),
Med3 = c("NaN","NaN","DM", "NaN","NaN"))
我尝试了以下方法:
dfx = df%>%
mutate(across(contains("Med", ignore.case = TRUE), str_remove(.,"NaN")))
Error: Problem with `mutate()` input `..1`.
x Problem with `across()` input `.fns`.
i Input `.fns` must be NULL, a function, a formula, or a list of functions/formulas.
i Input `..1` is `(function (.cols = everything(), .fns = NULL, ..., .names = NULL) ...`.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
Problem with `mutate()` input `..1`.
i argument is not an atomic vector; coercing
i Input `..1` is `(function (.cols = everything(), .fns = NULL, ..., .names = NULL) ...`.
dfx = df%>%
mutate(across(contains("Med", ignore.case = TRUE), str_remove("NaN")))
Error: Problem with `mutate()` input `..1`.
x argument "pattern" is missing, with no default
i Input `..1` is `(function (.cols = everything(), .fns = NULL, ..., .names = NULL) ...`.
我也有从单个列中删除字符串的问题,所以我想我可能会误解str_remove
dfy=df%>%
str_remove(string = Med1, pattern = "NaN")
Error in str_remove(., string = Med1, pattern = "NaN") :
unused argument (.)