用几列与小组创建小时的日期
嗨,我有一个带有4列的表DF_IN,如下所示。我在尝试每小时使用几列的小时创建日期时会出现错误。
Gender = c("Male","Female")
Sec = c("AA","BB")
min_date = c("12/1/2018","12/9/2018")
max_date = c("12/3/2018","12/10/2018")
df_in = data.frame(Gender,Sec,min_date,max_date)
对于第一行号,行将为72(3天 * 24小时),对于第二行48行(2天 * 24小时),
df_out看起来像
我已经尝试了以下代码,
df_out = df_in %>% group_by(Gender, Sec) %>% mutate (DateSeries = seq(as.POSIXct(min_date), as.POSIXct(max_date), by="hour"))
谢谢。
Hi I have a table df_in with 4 columns as shown below.I am getting error while trying to create dateseries on hourly basis with group by few columns.
Gender = c("Male","Female")
Sec = c("AA","BB")
min_date = c("12/1/2018","12/9/2018")
max_date = c("12/3/2018","12/10/2018")
df_in = data.frame(Gender,Sec,min_date,max_date)
for 1st row number of rows will be 72 (3 days * 24 hours) and for 2nd row 48 rows (2 days * 24 hours)
df_out will look like
I have tried with below code
df_out = df_in %>% group_by(Gender, Sec) %>% mutate (DateSeries = seq(as.POSIXct(min_date), as.POSIXct(max_date), by="hour"))
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会产生您需要的东西吗?
您在
突变
上的第一次努力无法使用,因为您正在尝试将721个元素向量添加到只有一行的数据框架中。展开
是您需要的功能:它创建其输入的“所有可能组合”版本。Does this produce what you need?
Your first effort with
mutate
won't work because you're trying to add a 721 element vector to a data frame with only one row.expand
is the function you need: it creates and "all possible combinations" version of its inputs.