我正在尝试删除不包含的数据框中的行。或_
基本上,保留具有的行。或_
我没有运气尝试过:test = filter(test,grepl(“ _ |。”,V1))其中V1是列的名称
test = filter(test,grepl("_|.",V1))
例如,从“ test”,“ test.com”,“ test_com”中,我只想保留“ test.com”和“ test_com”。
我正在尝试删除不包含的数据框中的行。或_
基本上,保留具有的行。或_
我没有运气尝试过:test = filter(test,grepl(“ _ |。”,V1))其中V1是列的名称
test = filter(test,grepl("_|.",V1))
例如,从“ test”,“ test.com”,“ test_com”中,我只想保留“ test.com”和“ test_com”。
.
在正则表达式中有特殊含义,您需要在grepl
中对其进行转义,请尝试
dplyr::filter(test,grepl("_|\\.",V1))
# V1
#1 test.com
#2 test_com
#3 test.com.
要删除以.
结尾的行,我们可以使用
dplyr::filter(test,!grepl("\\.$",V1))
# V1
#1 test
#2 test.com
#3 test_com
或在基数
中subset(test,!endsWith(V1,"."))
数据
test <- data.frame(V1 = c("test","test.com","test_com","test.com."),stringsAsFactors = FALSE)