【发布时间】:2019-12-10 12:32:58
【问题描述】:
我在 df 数据框中有一个 issue_date 列,表示日级数据。
根据输入的年份 (y) 和月份 (m),假设为 2020 年、2019 年和 2018 年以及 4 月和 6 月。我想对所有年份 (2018,19,20) 的 4 月和 6 月之间的数据进行子集化。
issue_date
1 2019-04-15
2 2019-04-15
3 2019-04-16
4 2019-04-16
5 2019-04-18
6 2019-04-23
我如何做到这一点?
【问题讨论】:
-
或者在基础 R 中:
subset(df, as.integer(format(issue_date, "%m")) %in% 4:6)假设issue_date已经属于 Date 类。