当字符串列值包含匹配字符串'时,在r中过滤数据帧

时间:2015-03-22 15:47:37

标签: r dataframe subset

我有以下格式的数据框

Question                Year
filter with question?   2010
keep this row           2009
keep this row too       2008
remove this one?        2007

预期结果

Question                Year
keep this row           2009
keep this row too       2008

获取不包括列的数据框子集问题包含问号'?'。

1 个答案:

答案 0 :(得分:1)

我们可以使用grep过滤掉“问题”列中的?元素

df1[!grepl('\\?', df1$Question),]
#           Question Year
#2     keep this row 2009
#3 keep this row too 2008