当字符串列值包含 'matching string' 时过滤 r 中的数据框
Filter data frame in r when string column value contains 'matching string'
我有以下格式的数据框
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
过滤掉'Question'列的?
个元素
df1[!grepl('\?', df1$Question),]
# Question Year
#2 keep this row 2009
#3 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
过滤掉'Question'列的?
个元素
df1[!grepl('\?', df1$Question),]
# Question Year
#2 keep this row 2009
#3 keep this row too 2008