I am having difficulty getting data to look how I would like after passing to map
. Currently, I have all the data I need in a list, but I would like the items in the list to become headers in a nested dataframe.
Below is the reprex
library(tsibble)
library(lubridate)
library(tsfeatures)
library(purrr)
# data prep
weather <- nycflights13::weather %>%
select(origin, time_hour, temp)
weather_tsbl <- as_tsibble(weather, key = id(origin), index = time_hour) %>%
spread(key = origin, value = temp)
# get tsfeatures
weather_tsbl %>%
select(-time_hour) %>%
map(~ts(.,frequency = 7)) %>% # pretend data is daily
map(~tsfeatures::acf_features(.))
#> $EWR
#> x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10
#> 0.9942173 8.6803613 0.4329437 0.6123397 -0.4438008 0.2030792
#> seas_acf1
#> 0.9051399
#>
#> $JFK
#> x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10
#> 0.9941960 8.8787780 0.2251941 0.2575175 -0.5206391 0.2810568
#> seas_acf1
#> 0.9204314
#>
#> $LGA
#> x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10
#> 0.9962239 9.1287769 0.3364568 0.4056202 -0.4828037 0.2391174
#> seas_acf1
#> 0.9386394
#>
#> $time_hour
#> x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1
#> 9.996557e-01 9.962177e+00 -5.999244e-04 3.369382e-06 -5.000000e-01
#> diff2_acf10 seas_acf1
#> 2.500000e-01 9.975902e-01
# make data look like this:
# origin data x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10 seas_acf1
# <chr> <list>
# 1 EWR <tibble [8,708 x 2]> 0.9942173 8.6803613 0.4329437 0.6123397 -0.4438008 0.2030792 0.9051399
# 2 JFK <tibble [8,711 x 2]> 0.9941960 8.8787780 0.2251941 0.2575175 -0.5206391 0.2810568 0.9204314
# 3 LGA <tibble [8,711 x 2]> 0.9962239 9.1287769 0.3364568 0.4056202 -0.4828037 0.2391174 0.9386394
Created on 2018-09-08 by the reprex package (v0.2.0).
The above code gives me all of the data I need, but I would like it in the following format.
# make data look like this:
# origin data x_acf1 x_acf10 diff1_acf1 diff1_acf10 diff2_acf1 diff2_acf10 seas_acf1
# <chr> <list>
# 1 EWR <tibble [8,708 x 2]> 0.9942173 8.6803613 0.4329437 0.6123397 -0.4438008 0.2030792 0.9051399
# 2 JFK <tibble [8,711 x 2]> 0.9941960 8.8787780 0.2251941 0.2575175 -0.5206391 0.2810568 0.9204314
# 3 LGA <tibble [8,711 x 2]> 0.9962239 9.1287769 0.3364568 0.4056202 -0.4828037 0.2391174 0.9386394
I know how to nest the data and join, but I don't know how to make the names, such as x_acf1
, headers in a dataframe.