我想使用存储在vector中的字符串从表中删除行:
> dput(vec_temp)
c("HL", "LL", "ML")
表格如下:
structure(list(Accession = "AT1G71220", variable = structure(14L, .Label = c("f:HL-f:FL",
"f:LL-f:FL", "f:ML-f:FL", "f:LL-f:HL", "f:ML-f:LL", "f:ML-f:HL",
"m:HL-m:FL", "m:LL-m:FL", "m:ML-m:FL", "m:LL-m:HL", "m:ML-m:HL",
"m:ML-m:LL", "ntrc:HL-ntrc:FL", "ntrc:LL-ntrc:FL", "ntrc:ML-ntrc:FL",
"ntrc:LL-ntrc:HL", "ntrc:ML-ntrc:HL", "ntrc:ML-ntrc:LL", "WT:HL-WT:FL",
"WT:LL-WT:FL", "WT:ML-WT:FL", "WT:LL-WT:HL", "WT:ML-WT:HL", "WT:ML-WT:LL"
), class = "factor"), value = 0.0445054204080209), .Names = c("Accession",
"variable", "value"), row.names = 2167L, class = "data.frame", na.action = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L), .Names = c("35", "199",
"363", "527", "691", "855", "1019", "1183", "1347", "1511", "1675",
"1839", "2003", "2331", "2495", "2659", "2823", "2987", "3151",
"3315", "3479", "3643", "3807"), class = "omit"))
请关注名为variable
的列。此表包含一行variable
- > ntrc:LL-ntrc:FL
。从这个线程的开头看向量,我们可以看到FL
不存在。因此,我想删除该行(通常是整个表)。我想请R将矢量中的字符串与variable
之后出现的名为:
的列中的字符串进行比较。如果在向量中找不到表中的字符串,则应删除整行(或表)。
答案 0 :(得分:2)
一个想法是拆分variable
列并使用grepl
来确定向量中的后缀是否出现在字符串两个次(因此{{1} }),即
== 2