gpt4 book ai didi

r - 如何根据句子中的一个字符串识别行

转载 作者:行者123 更新时间:2023-12-04 12:47:04 24 4
gpt4 key购买 nike

我最近问了一个非常有用的问题,我尝试使用相同的方法来找到我的解决方案

df<- structure(list(How = structure(c(2L, 2L, 2L, 1L, 2L, 2L, 2L, 
1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L), .Label = c("Ismainbody",
"IsmainbodyCandidate"), class = "factor"), No = c(12L, 38L, 38L,
3L, 49L, 38L, 85L, 4L, 38L, 57L, 38L, 5L, 6L, 10L, 4L, 12L, 38L,
7L, 8L, 61L), Main = structure(c(6L, 13L, 9L, 15L, 20L, 12L,
1L, 19L, 10L, 2L, 7L, 18L, 4L, 14L, 5L, 16L, 8L, 3L, 17L, 11L
), .Label = c("Daa_ASTRONOMY Iso 1B of Tn-1 TTT=ASTY ", "E7EUT5_ASTRONOMY gas TTT=ASTY BOO=3 ",
"ECO", "ECO transferase E [TTT=ASTY]", "ECO_ASTRONOMY karim, TTT=ASTY BOO=3",
"FSSZ1_ASTRONOMY Karim, tyBOO II brothers 74 TTT=ASTY BOO=3 ",
"H2A1A_ASTRONOMY tyBOO 1-A TTT=ASTY BOO=1 ", "H2A2B_ASTRONOMY tyBOO 2-B TTT=ASTY BOO=1 ",
"H2A3_ASTRONOMY Hammer H2A tyBOO 3 TTT=ASTY BOO=1 ", "H2AV_ASTRONOMY Iso 2 of TTT=ASTY ",
"H2E_ASTRONOMY ufidm TTT=ASTY ", "Hammer [TTT=ASTY]", "Hammer H2A tyBOO 2-C [TTT=ASTY]",
"Iso 2 of Deleted in house [TTT=ASTY]", "Iso 2019 of denis [TTT=ASTY]",
"K2C74_ASTRONOMY karim, tyBOO II TTT=ASTY BOO=1", "KAR_ASTRONOMY karim, tyBOO TTT=ASTY BOO=1 BBS",
"karim, tyBOO II 1b [TTT=ASTY]", "karim, tyBOO II 7 [TTT=ASTY]",
"Putative heat 7 [TTT=ASTY]"), class = "factor")), class = "data.frame", row.names = c(NA,
-20L))

这是我拥有的数据,我想删除其中包含以下字母的行:

卡里姆

环保



我喜欢这个
lookm <- c("karim", "ECO", "Daa") 
df2<- df[!df$Main %in% lookm, ]

但什么也没发生。我怎样才能做到这一点?

最佳答案

我们可以使用 grep

df[!grepl(paste(lookm, collapse="|"), df$Main),]

关于r - 如何根据句子中的一个字符串识别行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51940591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com