dplyr:在计数中取消引用无法识别列
dplyr:在计数中取消引用无法识别列,r,dplyr,R,Dplyr,getDupIds(测试,“名称”) 但我知道带下划线的函数(count)现在将被取消引号取代。但是,以下内容会引发错误: 错误:无法提取不存在的列。“名称”列不存在。 getDupIds <- function(df, id_type) { list <- df %>% count_(id_type) %>% filter(n > 1) %>% pull(id_type) list <- list[!is.na(
getDupIds(测试,“名称”)
但我知道带下划线的函数(count
)现在将被取消引号取代。但是,以下内容会引发错误:
错误:无法提取不存在的列。“名称”列不存在。
getDupIds <- function(df, id_type) {
list <- df %>%
count_(id_type) %>%
filter(n > 1) %>%
pull(id_type)
list <- list[!is.na(list)]
if (length(list) != 0) {
return(list)
} else {
return("No duplicate ids.")
}
}
getDupIds%
过滤器(n>1)%>%
拉力(id\U型)
在使用之前,先列出转换为符号代码>:
getDupIds <- function(df, id_type) {
list <- df %>%
count(!!id_type) %>%
filter(n > 1) %>%
pull(id_type)
list <- list[!is.na(list)]
if (length(list) != 0) {
return(list)
} else {
return("No duplicate ids.")
}
}
把它叫做:
list <- df %>%
count({{id_type}}) %>%
filter(n > 1) %>%
pull({{id_type}})
library(dplyr)
library(rlang)
getDupIds <- function(df, id_type) {
list <- df %>%
count(!!sym(id_type)) %>%
#You can also use
#count(.data[[id_type]]) %>%
filter(n > 1) %>%
pull(id_type)
list <- list[!is.na(list)]
if (length(list) != 0) return(list)
else return("No duplicate ids.")
}
getDupIds(test, "name")
#[1] 3
list <- df %>%
count({{id_type}}) %>%
filter(n > 1) %>%
pull({{id_type}})
getDupIds(test, name)