Redeem time period in r

2

Hello, I have a large series of temporal data. I have over 100 years to work. I need to recapture (abstract) only the summers of each of the years, and I do not know how to do in R. For example, I need the time period 20/06/2015 to 20/09/2015, and of the previous years as 2014, 2013, which are all contained together in the same series. Can someone help me with a formula or command?

    
asked by anonymous 01.10.2015 / 15:19

1 answer

1

I did not see how your data is strung so I invented a database. This sequence of operations will take only the period from 6/20 to 9/20 of all the years that are in the base.

library(lubridate)
library(dplyr)

dados <- data.frame(
  datas = seq(as.Date('1900-01-01'),as.Date('2000-12-31'),by = 1),
  valor = 1:36890
)

dados %>% tbl_df %>%
  # pegar apenas os meses de junho a setembro
  filter(month(datas) <= 9, month(datas) >= 6) %>%
  # se for junho, só pegar os dias maiores que 20
  filter(!(month(datas) == 6 & day(datas) < 20)) %>%
  # se for setembro pegar os dias menores do que 20
  filter(!(month(datas) == 9 & day(datas) > 20))

Source: local data frame [9,393 x 2]

        datas valor
       (date) (int)
1  1900-06-20   171
2  1900-06-21   172
3  1900-06-22   173
4  1900-06-23   174
5  1900-06-24   175
6  1900-06-25   176
7  1900-06-26   177
8  1900-06-27   178
9  1900-06-28   179
10 1900-06-29   180
..        ...   ...
    
02.10.2015 / 16:32