如何将日期格式重组为另一种格式以获得新列
我有这样的数据集,
DT=structure(list(date = c("01.01.2021", "01.01.2021", "01.01.2021",
"01.01.2021", "01.01.2021", "01.01.2021", "01.01.2021", "01.01.2021",
"01.01.2021", "01.01.2021", "01.01.2021", "01.02.2021", "01.02.2021",
"01.02.2021", "01.02.2021", "01.02.2021", "01.02.2021", "01.02.2021",
"01.02.2021", "01.02.2021"), sales_count = c(10L, 4L, 8L, 6L,
4L, 4L, 4L, 3L, 1L, 5L, 2L, 10L, 5L, 9L, 2L, 8L, 5L, 6L, 8L,
3L)), class = "data.frame", row.names = c(NA, -20L))
它看起来像这样
date sales_count
1 01.01.2021 10
2 01.01.2021 4
3 01.01.2021 8
4 01.01.2021 6
我怎样才能重新制作数据集,使其具有完全相同的输入格式
sales_count date_time date week_num weekday
1: 1 2016-05-02 00:00:00 2016-05-02 1 Monday
2: 10 2016-05-02 00:00:00 2016-05-02 1 Monday
3: 14 2016-05-02 00:00:00 2016-05-02 1 Monday
4: 15 2016-05-02 00:00:00 2016-05-02 1 Monday
5: 20 2016-05-02 00:00:00 2016-05-02 1 Monday
I have such dataset
DT=structure(list(date = c("01.01.2021", "01.01.2021", "01.01.2021",
"01.01.2021", "01.01.2021", "01.01.2021", "01.01.2021", "01.01.2021",
"01.01.2021", "01.01.2021", "01.01.2021", "01.02.2021", "01.02.2021",
"01.02.2021", "01.02.2021", "01.02.2021", "01.02.2021", "01.02.2021",
"01.02.2021", "01.02.2021"), sales_count = c(10L, 4L, 8L, 6L,
4L, 4L, 4L, 3L, 1L, 5L, 2L, 10L, 5L, 9L, 2L, 8L, 5L, 6L, 8L,
3L)), class = "data.frame", row.names = c(NA, -20L))
it looks something like this
date sales_count
1 01.01.2021 10
2 01.01.2021 4
3 01.01.2021 8
4 01.01.2021 6
How can I remake the dataset so that it has exactly this input format
sales_count date_time date week_num weekday
1: 1 2016-05-02 00:00:00 2016-05-02 1 Monday
2: 10 2016-05-02 00:00:00 2016-05-02 1 Monday
3: 14 2016-05-02 00:00:00 2016-05-02 1 Monday
4: 15 2016-05-02 00:00:00 2016-05-02 1 Monday
5: 20 2016-05-02 00:00:00 2016-05-02 1 Monday
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
lubridate
。我不确定您期望的预期输出中的日期与原始数据框相比是否不同。Using
lubridate
. I'm not sure you expect different dates in your expected output compared to your original dataframe.