同 tidyverse :
tidyverse
tags<-data.frame(tagName=c("opengl","openglGHSAJKGNKS","arc","arc93257","asnsgn")) tags%>% mutate(software = case_when( tagName %in% foss ~ "FOSS", grepl(paste(foss,collapse="|"),tagName) ~ "FOSS", tagName %in% cots ~ "COTS", grepl(paste(cots,collapse="|"), tagName) ~ "COTS", T ~ "other")) tagName software 1 opengl FOSS 2 openglGHSAJKGNKS FOSS 3 arc COTS 4 arc93257 COTS 5 asnsgn other
两件事情。首先,你需要 grepl() 因为逻辑输出。其次, grepl() 不适用于字符向量,因此您需要像这样折叠它 "anaconda|android|..." 并省略 fixed = TRUE 上班。
grepl()
"anaconda|android|..."
fixed = TRUE
这应该这样做:
tags$software <- ifelse(tags$tagName %in% foss, "FOSS", ifelse(grepl(paste(foss, collapse = "|"), tags$tagName), "FOSS", ifelse(tags$tagName %in% cots, "COTS", ifelse(grepl(paste(cots, collapse = "|"), tags$tagName), "COTS", "other"))))