Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incorrect key updating #47

Closed
earowang opened this issue Aug 6, 2018 · 0 comments
Closed

Incorrect key updating #47

earowang opened this issue Aug 6, 2018 · 0 comments
Labels

Comments

@earowang
Copy link
Member

earowang commented Aug 6, 2018

library(tsibble)
library(lubridate)
flights <- nycflights13::flights %>%
  mutate(
    sched_dep_datetime = make_datetime(year, month, day, hour, minute, 0),
    flight_num = paste0(carrier, flight)
  )
flights_tsbl <- flights %>%
  as_tsibble(
    key = id(flight_num), 
    index = sched_dep_datetime, 
    regular = FALSE
  )

The key should be updated from flight_num to origin, not NULL.

flights_tsbl %>% 
  group_by(origin) %>% 
  summarise(avg_delay = mean(dep_delay, na.rm = TRUE))
#> # A tsibble: 199,339 x 3 [!]
#>    origin sched_dep_datetime  avg_delay
#>  * <chr>  <dttm>                  <dbl>
#>  1 EWR    2013-01-01 05:15:00      2   
#>  2 EWR    2013-01-01 05:58:00     -4   
#>  3 EWR    2013-01-01 06:00:00      0.2 
#>  4 EWR    2013-01-01 06:07:00      0   
#>  5 EWR    2013-01-01 06:08:00     24   
#>  6 EWR    2013-01-01 06:10:00     -4   
#>  7 EWR    2013-01-01 06:15:00      0   
#>  8 EWR    2013-01-01 06:30:00     -4.25
#>  9 EWR    2013-01-01 06:36:00      8   
#> 10 EWR    2013-01-01 06:45:00     15.3 
#> # ... with 199,329 more rows

Created on 2018-08-06 by the reprex
package
(v0.2.0).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant