I have data as shown in the image, I want to filter the data by the year column, while ensuring that the months are continuous as in the picture below
filtered file, the format I want
I accomplished the above using the following
gs2_1959 <- filter(g2, Year == "1959/60")
gs2_1960 <- filter(g2, Year == "1960/61")
temp <- rbind(gs2_1959, gs2_1960)
But if there are many years this would be a painful process as I would have to filter for each year.
I have been trying with the for loop like this
for (i in seq_along(gs2_unique)){
gs_filter <- filter(g2, i %in% gs2_unique)
View(gs_filter)
} # where unique is the unique years in my data frame.
This retains the years in the original format (see the Raw data image). Raw image
Here is how I would do this: instead of having the date across three different columns, combine the Year, Day and Months column into one:
Output: