I have a data set that has multiple years assigned to an ID. I am trying to filter the data by summer months and winter months within a single year for each ID. For example I would like to get the summer and winter months of ID 1 for only 2010, only 2011, only 2012, and only 2013.
In the actual data set each ID varies in the number of years they have in the data set.
Here is what I have so far:
library(lubridate)
library(tidyverse)
date <- rep_len(seq(dmy("01-01-2010"), dmy("31-12-2013"), by = "days"),1000)
ID <- rep(seq(1, 5), 100)
df <- data.frame(date = date,
x = runif(length(date), min = 60000, max = 80000),
y = runif(length(date), min = 800000, max = 900000),
ID)
#Filters for the core summer months
summer <- df %>% arrange(ID, date) %>%
filter(month %in% 06:08)
# Filters for the core winter months
winter <- df %>% arrange(ID, date) %>%
filter(month %in% c(01,02,03))
I am trying to get two data frames: summer months and winter months, and within those data frames I want it separate the seasons by year for each ID. I hope that makes sense.