r - 当字符串列值包含 'matching string' 时过滤 r 中的数据框

标签 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

获取数据框的子集,排除列问题包含问号“?”。

最佳答案

我们可以使用 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/

相关文章:

python - 从每行的最大值中减去最小值,Python Pandas DataFrame

python - 比较并连接两个数据框中的两列

r - 在 R 中,如何通过来自另一个 data.frame 的值对 data.frame 进行子集?

r - 如何在操作、远程R工作区和RStudio服务器中选择R服务器的R作为默认值?

python - 通过绘制县等值区域图添加更多关于悬停的数据

performance - 数据帧子集性能

Python 查找满足特定条件的列表列表的子集

r - 在 R 中使用函数指定参数名称

r - POSIXct 日期匹配(可能很简单!)

arrays - R将data.frame转换为json