我有以下格式的数据框
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
关于r - 当字符串列值包含 'matching string' 时过滤 r 中的数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29196394/