我正在尝试使用该tidyselect
函数where
并pivot_longer
收到tidyselect
包不支持谓词的错误。这似乎有点不合理,所以很可能我有语法错误。(我意识到 SO 不适用于代码调试。)我认为如果有人能告诉我如何完成这项任务,它会帮助我更好地理解。
d <- dplyr::tribble(
~cups, ~glasses,
"YES", "NO",
"NO" , "YES",
"YES", "NO",
"YES", "NO",
"NO" , "YES",
"YES", "NO",
"NO" , "YES",
"NO" , "YES",
"YES", "NO",
"NO" , "YES",
"YES", "NO",
"NO" , "YES",
"abc", "def"
) %>%
mutate(id = row_number())
这给出了我想要的结果。
the_columns_I_want <- c('cups','glasses')
d %>%
pivot_longer(all_of(the_columns_I_want),values_to = 'result', names_to = 'group')
但我想选择某些类型的字段。
d %>%
pivot_longer(where(is.character),values_to = 'result', names_to = 'group')
证明它确实适用dplyr
,所以我没有犯这个错误:(Tidyverse:这个 tidyselect 接口还不支持谓词)
d %>%
select(where(is.character))