tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
528 stars 50 forks source link

filter_index() does not work for weekly index if week_start is not the default #261

Closed pgg1309 closed 2 years ago

pgg1309 commented 2 years ago

The filter_index() fails when 'week_start' is not the default

The filter_index fails when working with yearweek types if the 'week_start' is not the default. See below.

# example
library(tidyverse)
library(tsibble)

wk1 <- yearweek("2020 W01", week_start = 1)
wk2 <- yearweek("2021 W20", week_start = 1)
dates <- seq(from = wk1, to = wk2, by = 1)

wk1 <- yearweek("2020 W01", week_start = 7)
wk2 <- yearweek("2021 W20", week_start = 7)
dates1 <- seq(from = wk1, to = wk2, by = 1)

x <- rnorm(73)
x<-cumsum(x)

db <- tsibble(week = dates, values = x, index = week)
db1 <- tibble(week = dates1, values = x, index = week)

filter_index(db, "2021" ~ . )
filter_index(db1, "2021" ~ . )
filter_index(db1, "2021" ~ . , weekstart = 7)
filter_index(db1, yearweek("2021", week_start = 7) ~ . )
earowang commented 2 years ago

thanks, fixed.

Cheers, Earo

On 24 Sep 2021, at 7:49, Paulo Grahl wrote:

The filter_index() fails when 'week_start' is not the default

The filter_index fails when working with yearweek types if the 'week_start' is not the default. See below.

# example
library(tidyverse)
library(tsibble)

wk1 <- yearweek("2020 W01", week_start = 1)
wk2 <- yearweek("2021 W20", week_start = 1)
dates <- seq(from = wk1, to = wk2, by = 1)

wk1 <- yearweek("2020 W01", week_start = 7)
wk2 <- yearweek("2021 W20", week_start = 7)
dates1 <- seq(from = wk1, to = wk2, by = 1)

x <- rnorm(73)
x<-cumsum(x)

db <- tsibble(week = dates, values = x, index = week)
db1 <- tibble(week = dates1, values = x, index = week)

filter_index(db, "2021" ~ . )
filter_index(db1, "2021" ~ . )
filter_index(db1, "2021" ~ . , weekstart = 7)
filter_index(db1, yearweek("2021", week_start = 7) ~ . )

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/tidyverts/tsibble/issues/261