# NOT RUN {
# Sum over sensors ----
pedestrian %>%
summarise(Total = sum(Count))
# Back to tibble
pedestrian %>%
as_tibble() %>%
summarise(Total = sum(Count))
# 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)
)
stocks %>% gather(stock, price, -time)
# 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)
)
stocksm <- stocks %>% gather(stock, price, -time)
stocksm %>% spread(stock, price)
nested_stock <- stocksm %>%
nest(-stock)
stocksm %>%
group_by(stock) %>%
nest()
nested_stock %>%
unnest(key = id(stock))
stock_qtl <- stocksm %>%
group_by(stock) %>%
index_by(day3 = lubridate::floor_date(time, unit = "3 day")) %>%
summarise(
value = list(quantile(price)),
qtl = list(c("0%", "25%", "50%", "75%", "100%"))
)
unnest(stock_qtl, key = id(qtl))
# }
Run the code above in your browser using DataLab