• arrange(): if not arranging key and index in past-to-future order, a warning is likely to be issued.

  • slice(): if row numbers are not in ascending order, a warning is likely to be issued.

  • select(): keeps the variables you mention as well as the index.

  • transmute(): keeps the variable you operate on, as well as the index and key.

  • summarise() reduces a sequence of values over time instead of a single summary, as well as dropping empty keys/groups.

# S3 method for tbl_ts
arrange(.data, ...)

# S3 method for tbl_ts
filter(.data, ..., .preserve = FALSE)

# S3 method for tbl_ts
slice(.data, ..., .preserve = FALSE)

# S3 method for tbl_ts
select(.data, ...)

# S3 method for tbl_ts
rename(.data, ...)

# S3 method for tbl_ts
mutate(.data, ...)

# S3 method for tbl_ts
transmute(.data, ...)

# S3 method for tbl_ts
summarise(.data, ...)

# S3 method for tbl_ts
gather(data, key = "key", value = "value", ...,
  na.rm = FALSE, convert = FALSE, factor_key = FALSE)

# S3 method for tbl_ts
spread(data, key, value, ...)

# S3 method for tbl_ts
nest(.data, ...)

Arguments

.data

A tbl_ts.

...

Same arguments accepted as its tidyverse generic.

.preserve

when FALSE (the default), the grouping structure is recalculated based on the resulting data, otherwise it is kept as is.

data

A data frame.

key

Names of new key and value columns, as strings or symbols.

This argument is passed by expression and supports quasiquotation (you can unquote strings and symbols). The name is captured from the expression with rlang::ensym() (note that this kind of interface where symbols do not represent actual objects is now discouraged in the tidyverse; we support it here for backward compatibility).

value

Names of new key and value columns, as strings or symbols.

This argument is passed by expression and supports quasiquotation (you can unquote strings and symbols). The name is captured from the expression with rlang::ensym() (note that this kind of interface where symbols do not represent actual objects is now discouraged in the tidyverse; we support it here for backward compatibility).

na.rm

If TRUE, will remove rows from output where the value column is NA.

convert

If TRUE will automatically run type.convert() on the key column. This is useful if the column types are actually numeric, integer, or logical.

factor_key

If FALSE, the default, the key values will be stored as a character vector. If TRUE, will be stored as a factor, which preserves the original ordering of the columns.

Details

Column-wise verbs, including select(), transmute(), summarise(), mutate() & transmute(), keep the time context hanging around. That is, the index variable cannot be dropped for a tsibble. If any key variable is changed, it will validate whether it's a tsibble internally. Use as_tibble() to leave off the time context.

Examples

library(dplyr, warn.conflicts = FALSE) # Sum over sensors pedestrian %>% index_by() %>% summarise(Total = sum(Count))
#> # A tsibble: 17,542 x 2 [1h] <Australia/Melbourne> #> Date_Time Total #> <dttm> <int> #> 1 2015-01-01 00:00:00 2866 #> 2 2015-01-01 01:00:00 1535 #> 3 2015-01-01 02:00:00 994 #> 4 2015-01-01 03:00:00 569 #> 5 2015-01-01 04:00:00 311 #> 6 2015-01-01 05:00:00 159 #> 7 2015-01-01 06:00:00 129 #> 8 2015-01-01 07:00:00 146 #> 9 2015-01-01 08:00:00 258 #> 10 2015-01-01 09:00:00 419 #> # … with 17,532 more rows
# shortcut pedestrian %>% summarise(Total = sum(Count))
#> # A tsibble: 17,542 x 2 [1h] <Australia/Melbourne> #> Date_Time Total #> <dttm> <int> #> 1 2015-01-01 00:00:00 2866 #> 2 2015-01-01 01:00:00 1535 #> 3 2015-01-01 02:00:00 994 #> 4 2015-01-01 03:00:00 569 #> 5 2015-01-01 04:00:00 311 #> 6 2015-01-01 05:00:00 159 #> 7 2015-01-01 06:00:00 129 #> 8 2015-01-01 07:00:00 146 #> 9 2015-01-01 08:00:00 258 #> 10 2015-01-01 09:00:00 419 #> # … with 17,532 more rows
# Back to tibble pedestrian %>% as_tibble() %>% summarise(Total = sum(Count))
#> # A tibble: 1 x 1 #> Total #> <int> #> 1 45483871
library(tidyr) # example from tidyr stocks <- tsibble( time = as.Date("2009-01-01") + 0:9, X = rnorm(10, 0, 1), Y = rnorm(10, 0, 2), Z = rnorm(10, 0, 4) )
#> Using `time` as index variable.
(stocksm <- stocks %>% gather(stock, price, -time))
#> # A tsibble: 30 x 3 [1D] #> # Key: stock [3] #> time stock price #> <date> <chr> <dbl> #> 1 2009-01-01 X -1.22 #> 2 2009-01-02 X 0.0849 #> 3 2009-01-03 X 0.581 #> 4 2009-01-04 X 0.451 #> 5 2009-01-05 X 0.497 #> 6 2009-01-06 X 0.779 #> 7 2009-01-07 X 1.51 #> 8 2009-01-08 X -1.82 #> 9 2009-01-09 X 0.788 #> 10 2009-01-10 X -0.973 #> # … with 20 more rows
stocksm %>% spread(stock, price)
#> # A tsibble: 10 x 4 [1D] #> time X Y Z #> <date> <dbl> <dbl> <dbl> #> 1 2009-01-01 -1.22 1.79 -2.50 #> 2 2009-01-02 0.0849 1.53 -3.50 #> 3 2009-01-03 0.581 1.30 1.14 #> 4 2009-01-04 0.451 -1.07 1.38 #> 5 2009-01-05 0.497 -0.168 -3.74 #> 6 2009-01-06 0.779 -4.02 1.17 #> 7 2009-01-07 1.51 -1.03 0.191 #> 8 2009-01-08 -1.82 0.203 1.78 #> 9 2009-01-09 0.788 -0.112 2.67 #> 10 2009-01-10 -0.973 -4.86 -1.25
nested_stock <- stocksm %>% nest(-stock) stocksm %>% group_by(stock) %>% nest()
#> # A tibble: 3 x 2 #> stock data #> <chr> <list> #> 1 X <tsibble [10 × 2]> #> 2 Y <tsibble [10 × 2]> #> 3 Z <tsibble [10 × 2]>