[英]Stumped by 'no applicable method for 'filter_' applied to an object of class "character"' error
I have a data frame with two relevant columns: name, id我有一个包含两个相关列的数据框:名称、ID
I have a list of regexes which I'd like to match against the values in the name column and return the id value on the same row.我有一个正则表达式列表,我想将其与 name 列中的值进行匹配,并在同一行返回 id 值。
It works if I pass a single value, but when I try lapply, I get this error:如果我传递单个值,它会起作用,但是当我尝试 lapply 时,我收到此错误:
Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "character" UseMethod("filter_") 中的错误:没有适用于“filter_”的方法应用于“character”类的对象
id <- c(1:10)
name <- c("a_able", "b_baker", "c_charlie", "d_delta", "e_echo", "f_foxtrot", "g_golf", "h_hotel", "i_indigo", "j_juliet")
t <- tibble(id, name)
prefix <- c("^c_", "^f_", "^g_")
matchingName <- function(tibbleName, pattern){
return(tibbleName %>% filter(str_detect(name, pattern)) %>% select(id))
}
matchingName(t, prefix[1])
# A tibble: 1 x 1
id
<int>
1 3
lapply(prefix, matchingName, t)
Error in UseMethod("filter_") :
no applicable method for 'filter_' applied to an object of class "character"
Called from: filter_(.data, .dots = compat_as_lazy_dots(...))
I expect to get a list of ids (3,6,7).我希望得到一个 id 列表(3,6,7)。 I get the error message instead.我收到了错误消息。
已解决,参数规范的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.