[英]R: Is there a way to Vlookup with partial match between two dataframes columns
Instead of the pictures, you should try to put the data in reproducible format.而不是图片,您应该尝试以可重现的格式放置数据。 Also, try to show some work but I can understand that you may not know where to even begin.另外,尝试展示一些作品,但我可以理解你可能不知道从哪里开始。 But at least show what you have attempted whether it works or not.但至少展示你尝试过的东西是否有效。
Will something like this work?这样的事情会起作用吗?
library(dplyr)
df1 <- data.frame(almId = c(12347, 123455, 112625, 112621), almname = c("1001 battery down", "2077 Power issue", "7166 DG fault", "2122 cable cut"))
df2 <- data.frame(almname = c("battery down", "Power issue", "DG fault", "Circuit break"))
k <- paste0(df2$almname, collapse = "|")
df1 %>% mutate(Stat = stringr::str_detect(.$almname, k))
df3 <- df1 %>% mutate(Stat = stringr::str_detect(.$almname, k))
almId almname Stat
1 12347 1001 battery down TRUE
2 123455 2077 Power issue TRUE
3 112625 7166 DG fault TRUE
4 112621 2122 cable cut FALSE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.