根据日期 提取场年季效应

1, 提取准者

根据年-月-日, 提取年+季节

  • 根据日期的年,提取年
  • 根据日期的月,提取季节
  • 将两者合并

2. 示例

> head(test)
  ID Ceding_dat
1  1 2015-07-10
2  2 2015-07-10
3  3 2015-08-12
4  4 2016-02-28
5  5 2016-04-26
6  6 2016-04-26

对数据Ceding_dat,提取年和季:

如何提取季节,月份,使用lubridate包:

test$CNJ = paste0(year(test$Ceding_dat),quarter(test$Ceding_dat))
head(test)

结果:

> head(test)
  ID Ceding_dat   CNJ
1  1 2015-07-10 20153
2  2 2015-07-10 20153
3  3 2015-08-12 20153
4  4 2016-02-28 20161
5  5 2016-04-26 20162
6  6 2016-04-26 20162

3. 代码解释

使用R包lubridate·,提取年份,提取季节,使用paste0将两者合并在一起,然后复制给test,命名为CNJ。

祝你成功!

发布了245 篇原创文章 · 获赞 89 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/yijiaobani/article/details/102896516