【发布时间】:2014-04-03 08:30:52
【问题描述】:
我正在尝试删除数据框中包含某个单词或某些单词序列的行。例如:
mydf <- as.data.frame(read.xlsx("C:\\data.xlsx, 1, header=T"))
head(df)
# NO ARTICLE
# 1 34 New York Times reports blabla
# 2 42 Financial Times reports blabla
# 3 21 Greenwire reports blabla
# 4 3 New York Times reports blabla
# 5 46 Newswire reports blabla
我想从我的data.frame 中删除包含字符串“New York Times”和“Newswire”的行。我尝试过使用%in% 或grep 的不同方法,但我不太确定如何使用它!
我该怎么做?
【问题讨论】:
-
df[!grepl('New York Times',df$Article),]等 -
@Thomas - 你为什么不发布答案?