在R中将日期和时间分隔为两列,并根据一天中的时间汇总行

在R中将日期和时间分隔为两列,并根据一天中的时间汇总行,r,dplyr,tidyverse,tidyr,R,Dplyr,Tidyverse,Tidyr,如何将日期和时间分为两列?然后总结所有这些行,取一天中每12小时的平均值?(基本上每天只有两卷数据,而不是49卷,每卷是一天中第一/第二个12小时的平均温度。)请参见下面的图片,非常感谢您的帮助 当前代码: test <- weather %>% unite(date, Year.Month.Day.Hour.Minutes.in.YYYY, MM, DD, sep="-") %>% unite(time, HH24, MI.format.in.

如何将日期和时间分为两列?然后总结所有这些行,取一天中每12小时的平均值?(基本上每天只有两卷数据,而不是49卷,每卷是一天中第一/第二个12小时的平均温度。)请参见下面的图片,非常感谢您的帮助

当前代码:

test <- weather %>% 
  unite(date, Year.Month.Day.Hour.Minutes.in.YYYY, MM, DD, sep="-") %>% 
  unite(time, HH24, MI.format.in.Local.time, sep=":") %>% 
  mutate(timestamp=paste(date, time) %>% 
           as.POSIXct(., format="%Y-%m-%d %H:%M")) %>%
  select(timestamp, temperature)
test%
统一(日期,年.月.日.小时.分钟.英寸.年,月,日,九月=“-”%>%
统一(时间,HH24,MI.format.in.Local.time,sep=“:”)%>%
变异(时间戳=粘贴(日期、时间)%>%
as.POSIXct(,format=“%Y-%m-%d%H:%m”))%>%
选择(时间戳、温度)
电流输出:

预期产出: 像这样的事

weather %>% 
  unite(date, Year.Month.Day.Hour.Minutes.in.YYYY, MM, DD, sep="-") %>% 
  unite(time, HH24, MI.format.in.Local.time, sep=":") %>% 
  mutate(timestamp=paste(date, time) %>% 
           as.POSIXct(., format="%Y-%m-%d %H:%M")) %>%
  select(timestamp, temperature) %>% 
  group_by(
    Date = as.Date(timestamp), 
    Time = if_else(lubridate::am(timestamp), "Morning", "Afternoon")
  ) %>% 
  summarise(
    `Average Temperature` = mean(Air.Temperature.in.degrees.C)
  )
像这样的

weather %>% 
  unite(date, Year.Month.Day.Hour.Minutes.in.YYYY, MM, DD, sep="-") %>% 
  unite(time, HH24, MI.format.in.Local.time, sep=":") %>% 
  mutate(timestamp=paste(date, time) %>% 
           as.POSIXct(., format="%Y-%m-%d %H:%M")) %>%
  select(timestamp, temperature) %>% 
  group_by(
    Date = as.Date(timestamp), 
    Time = if_else(lubridate::am(timestamp), "Morning", "Afternoon")
  ) %>% 
  summarise(
    `Average Temperature` = mean(Air.Temperature.in.degrees.C)
  )

请以可复制的形式添加数据,以便我们复制和使用。图像没有帮助请以可复制的形式添加数据,我们可以复制和使用。图像没有帮助