![](/img/trans.png)
[英]How do I add calendar dates to an existing data table so that an entire month is accounted for in R?
[英]How do I sort dates by month in R?
新 R 学生在这里。 我正在尝试按月对数据进行排序。 这是我需要使用的数据示例,然后是代码,然后是我的结果。 有关如何完成此操作的任何提示? 我超级卡...
这是我一直在尝试的最新代码:
library(readr)
weather <- read_csv("R/weather.csv", col_types = cols(High = col_number(),
Low = col_number(), Precip = col_number(),
Snow = col_number(), Snowd = col_integer()))
View(weather)
library(ggplot2)
library(ggridges)
library(dplyr)
library(lubridate)
class(weather) #what class is dataset = dataframe
head(weather) #structure of the dataset
weather.month <- weather %>% # Group data by month
mutate(weather, 'month') %>%
group_by(month = lubridate::floor_date(weather$Day, 'month')) %>%
summarise(weather.month$High)
任何帮助解决这个问题将不胜感激!!!
可以通过将Day
转换为Date
class 来修改代码(使用mdy
或dmy
- 因为不清楚它是月-日-年还是日-月-年格式),然后按“月”应用floor_date
并应用高柱上的function
library(dplyr)
library(lubridate)
weather %>% #
group_by(month = lubridate::floor_date(mdy(Day), 'month')) %>%
summarise(High = sum(High, na.rm = TRUE))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.