【发布时间】:2014-06-24 00:27:42
【问题描述】:
我有一个这样的数据框 DF:
ID name description
1 Jen brooklyn new york cqre center
2 Chris santa monica barbers
3 Jeff chicago blah blah
4 Steve groomers are here
5 Mary chicken time
6 John and here we go
我想删除包含城市名称的行。我有一个包含城市名称(cityVec)的向量,但这不起作用。
f
【问题讨论】:
-
试试
DF[-grep(paste(cityVec,collapse="|"), DF$description, ignore.case=TRUE),] -
我收到以下错误: grep 错误(paste(cityVec, collapse = "|"), DF$description, ignore.case = TRUE) : 正则表达式在此语言环境中无效
-
你的数据中可能有这样的字符
"é",请确认 -
我认为问题在于它是一个向量。 Grep 适用于单个字符串,但包含字符串的向量似乎不起作用
-
在下面查看我的答案,它与@jdharrison 的答案相同,
grep确实适用于字符串向量,您能否发布str(DF)的输出,grep将不起作用如果DF$description是因素
标签: r