将包中的多种功能应用于分组数据

时间:2019-10-16 20:16:48

标签: r

我想滚动应用某些功能。我有一些类似于以下内容的数据:

weather <- nycflights13::weather %>% 
  select(origin, time_hour, temp)

library(tsfeatures)
functions <- ls("package:tsfeatures")[1:42]
functions <- sample(functions, 2)

数据如下:

# A tibble: 26,115 x 3
   origin time_hour                   temp
   <chr>  <dttm>                     <dbl>
 1 EWR    2013-01-01 01:00:00.000000  39.0
 2 EWR    2013-01-01 02:00:00.000000  39.0
 3 EWR    2013-01-01 03:00:00.000000  39.0
 4 EWR    2013-01-01 04:00:00.000000  39.9
 5 EWR    2013-01-01 05:00:00.000000  39.0
 6 EWR    2013-01-01 06:00:00.000000  37.9
 7 EWR    2013-01-01 07:00:00.000000  39.0
 8 EWR    2013-01-01 08:00:00.000000  39.9
 9 EWR    2013-01-01 09:00:00.000000  39.9
10 EWR    2013-01-01 10:00:00.000000  41  
# ... with 26,105 more rows

我想在天气数据上映射functions的位置(使用tsfunction默认值)

以下内容无效:

weather %>%
  group_by(origin) %>%
  nest() %>%
  mutate(
    tsdata = map(data ~zoo::rollapply(functions(temp)))
  )

0 个答案:

没有答案