gpt4 book ai didi

r - 有没有办法在 dplyr 的 na_if 函数中列出值?

转载 作者:行者123 更新时间:2023-12-04 14:47:03 25 4
gpt4 key购买 nike

<分区>

我想列出一个 tibble 中出现的所有事件,我想使用 dplyr 包中的 na_if 函数将其转换为缺失,但我似乎没有做对。有线索吗?

library(dplyr)

set.seed(123)

df <- tibble(
a1 = c("one", "three", "97", "twenty", "98"),
a2 = c("R", "Python", "99", "Java", "97"),
a3 = c("statistics", "Data", "Programming", "99", "Science"),
a4 = floor(rnorm(5, 80, 2))
)

#--- The long route

df1 <- df %>%
mutate(across(where(is.character), ~na_if(., "97")),
across(where(is.character), ~na_if(., "98")),
across(where(is.character), ~na_if(., "99")))

#---- Trial

df2 <- df %>%
mutate(across(where(is.character),
~na_if(., c("97", "98", "99"))))

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com