【发布时间】:2020-11-18 21:04:38
【问题描述】:
我需要提取日历周+年和月+年以指示我的数据中的同类群组。
示例数据:
da = data.frame(start_timestamp = c("1453598257", "1434619797","2016-02-23"))
da
start_timestamp
1 1453598257
2 1434619797
3 1456324104
我想添加以下变量:
- startcalendarweek:表示start_timestamp的日历周+年份
- startmonth:表示start_timestamp的月份+年份
- cohort_startweek:表示基于 startcalendarweek 的队列(1 = 2015 年第 1 日历周,2 = 2015 年第 2 日历周等)
- cohort_startmonth:表示基于开始月份的同类群组(1 = 2015 年 1 月,2 = 2015 年 2 月等)
输出数据:
da
start_timestamp startcalendarweek startmonth cohort_startweek cohort_startmonth
1 1453598257 4_2016 january2016 55 13
2 1434619797 25_2015 june2015 24 6
3 1456324104 8_2016 february2016 60 14
【问题讨论】:
标签: r time dplyr timestamp lubridate