我要删除所有带有*字符的行。
当我尝试删除*时-它只会删除所有内容
(“ *”-如何避免选择所有内容?)
xx <- data.frame(
c1=c(".", ".", ".", ".", ".", "*", ".", ".", "."),
c2=c(".", ".", ".", ".", "Q", "Q", "R", ".", "."),
c3=c(".", ".", ".", ".", "W", "*", ".", ".", "."),
c4=c("A", "A", ".", ".", "I", ".", "P", ".", "."),
c5=c(".", ".", ".", ".", "D", "Q", "D", ".", "."),
c6=c(".", ".", ".", ".", "*", ".", ".", ".", "."),
c7=c(".", ".", ".", ".", "W", ".", ".", ".", "."),
row.names = paste0("r", 1:9)
)
xx[!grepl('*', xx),]
dplyr::filter(xx, !grepl('*', c1))
xx %>%
+ filter(!str_detect(xx, '*'))
结果不应包含带有“ *”的行
(删除第5行和第6行,因为它们带有*)
structure(list(c1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("-",
".", "*"), class = "factor"), c2 = structure(c(1L, 1L, 1L, 1L,
4L, 1L, 1L), .Label = c(".", "A", "Q", "R", "T"), class = "factor"),
c3 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(".",
"*", "S", "W"), class = "factor"), c4 = structure(c(2L, 2L,
1L, 1L, 4L, 1L, 1L), .Label = c(".", "A", "I", "P", "V"), class = "factor"),
c5 = structure(c(1L, 1L, 1L, 1L, 3L, 1L, 1L), .Label = c(".",
"A", "D", "K", "Q"), class = "factor"), c6 = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("-", ".", "*"), class = "factor"),
c7 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("-",
".", "W"), class = "factor")), row.names = c("r1", "r2",
"r3", "r4", "r7", "r8", "r9"), class = "data.frame")
谢谢!
答案 0 :(得分:1)
如果我们使用CollectionViewCell
,则grep
是表示任何零个或多个字符的元字符。我们可以使用*
或转义(fixed = TRUE
)来获取文字值
\\*
或者另一个选择是xx[!Reduce(`|`, lapply(xx, function(x) grepl("*", x, fixed = TRUE))),]
来匹配==
,使用*
来获取连续的匹配计数以及子集
rowSums