【发布时间】:2016-07-01 21:37:34
【问题描述】:
我读过其他文章,例如:
Selecting rows where a column has a string like 'hsa..' (partial string match)
How do I select variables in an R dataframe whose names contain a particular string?
Subset data to contain only columns whose names match a condition
但大多数都是简单的修复:
- 他们只有一个字符串可以匹配
- 他们只有一个部分字符串可以匹配
所以我在这里寻求帮助。
假设我们有一个这样的示例数据表:
sample = data.table('Feb FY2016', 50)
sample = rbind(sample, list('Mar FY2017', 30))
sample = rbind(sample, list('Feb FY2017', 40))
sample = rbind(sample, list('Mar FY2016', 10))
colnames(sample) = c('month', 'unit')
如何对数据进行子集化,以便我的数据仅包含“月”列满足以下要求的行:
- 有 2016 年
- 从“三月”或“二月”开始
谢谢!
【问题讨论】: