R 当字符串列值包含';匹配字符串';

R 当字符串列值包含';匹配字符串';,r,dataframe,subset,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

我有以下格式的数据框

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

获取数据框的子集,不包括包含问号“?”的列。我们可以使用
grep
过滤掉“问号”列中的
元素

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

酷。很好!谢谢我是r方面的初学者,我在网上找到的大部分帮助都是如何轻松地获取数值滤波器的子集,没有问题。在需要在字符串中查找模式的情况下,
grep
可以正常工作。