简体   繁体   English

被应用于“字符”类对象的“没有适用的“过滤器_”方法错误困扰

[英]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.

相关问题 pmap 中的错误 UseMethod(&quot;filter_&quot;) 中的错误:没有适用于“filter_”的方法应用于“character”类的对象 - error in a pmap Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "character" UseMethod(“filter_”)中的错误:没有适用于“filter_”的方法应用于 class“c('double','numeric')”的 object - Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "c('double', 'numeric')" UseMethod(“filter_”)中的错误:没有适用于“filter_”的方法应用于 class“函数”的 object - Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "function" 没有适用于 'filter_' 的方法应用于 class "c('double', 'numeric')" 的 object - no applicable method for 'filter_' applied to an object of class "c('double', 'numeric')" R闪亮过滤器没有适用于“filter_”的方法应用于“函数”类的对象 - R shiny filter no applicable method for 'filter_' applied to an object of class "function" 使用“count”时,没有适用于“filter_”的方法应用于 class “c('double', 'numeric')”的 object - no applicable method for 'filter_' applied to an object of class “c('double', 'numeric')” when using `count` UseMethod(“select”)中的错误:没有适用于“select”的方法应用于 class“字符”的 object - Error in UseMethod("select") : no applicable method for 'select' applied to an object of class "character" 没有适用于“lme”的方法应用于 class“字符”的 object - No applicable method for 'lme' applied to an object of class "character" 出现错误:UseMethod(“过滤器”)中的错误:没有适用于“过滤器”的方法应用于 class “逻辑”的 object - Getting error: Error in UseMethod("filter") : no applicable method for 'filter' applied to an object of class "logical" R-Project没有适用于“元”类对象的“元”适用方法 - R-Project no applicable method for 'meta' applied to an object of class “character”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM