R 数据帧列表上的映射函数

R 数据帧列表上的映射函数,r,purrr,R,Purrr,我试图对我的数据应用一系列函数,但是我有一点出错 这些函数可以创建多个列,因此我使用bind_rows将它们添加到原始数据中 我想做的是将functions和map中的两个函数放在一个列表上,在每个列表中创建新列,我想使用mutate或summary library(tsfeatures) library(dplyr) library(purrr) functions <- c("stl_features", "max_kl_shift") Data %>% map(.,

我试图对我的数据应用一系列函数,但是我有一点出错

这些函数可以创建多个列,因此我使用
bind_rows
将它们添加到原始数据中

我想做的是将
functions
map
中的两个函数放在一个列表上,在每个列表中创建新列,我想使用
mutate
summary

library(tsfeatures)
library(dplyr)
library(purrr)

functions <- c("stl_features", "max_kl_shift")

Data %>% 
  map(., ~ map(., ~ data.frame(
    bind_cols(
      tsfeatures(.x["Value"], functions)
    )
  )
  )
  ) 
库(tsfeatures)
图书馆(dplyr)
图书馆(purrr)
功能%
map(,~map(,~data.frame)(
捆扎(
tsfeatures(.x[“值”],函数)
)
)
)
) 
错误:

近似值中的错误(idx,x[idx],tt,规则=2):至少需要两个 要插入的非NA值:警告消息:1:In min(x):min没有未丢失的参数;返回Inf 2:最大值(x): 最大值没有未丢失的参数;返回-Inf

数据:


Data示例列表中的数据框
Data
仅包含两行,这对于
tsfeatures
功能来说太小了。另一个问题是当您执行
.x[“Value”]
时,输出是一个数据帧,但是
tsfeatures
函数的文档说明第一个参数应该是一个单变量时间序列对象列表或向量。因此,我假设您应该使用的代码是
.x[[“Value”]]
,这将生成一个向量

我将
data
中的所有数据帧组合到一个数据帧中,尝试如下示例

tsfeatures(bind_rows(Data)[["Value"]], functions)
这将导致以下输出

# # A tibble: 1 x 10
#     nperiods seasonal_period trend      spike linearity curvature  e_acf1 e_acf10 max_kl_shift time_kl_shift
#        <dbl>           <dbl> <dbl>      <dbl>     <dbl>     <dbl>   <dbl>   <dbl>        <dbl>         <dbl>
#   1        0               1 0.965 0.00000631      2.99     -2.64 -0.0723   0.381           NA            NA

我想这可能会奏效。

谢谢!当我应用你的解决方案时,我在ts(x)中得到
错误:'ts'对象必须有一个或多个观察值
-我现在将处理一些更好的数据,并在5分钟左右更新你。好的,我添加了更多数据。现在每个数据帧都有20行。实际上,我认为您的原始解决方案在
data%>%map(,~tsfeatures(.x[[“Value”]],functions)]
中工作得非常好!我会再检查一下,让你知道!
# # A tibble: 1 x 10
#     nperiods seasonal_period trend      spike linearity curvature  e_acf1 e_acf10 max_kl_shift time_kl_shift
#        <dbl>           <dbl> <dbl>      <dbl>     <dbl>     <dbl>   <dbl>   <dbl>        <dbl>         <dbl>
#   1        0               1 0.965 0.00000631      2.99     -2.64 -0.0723   0.381           NA            NA
Data %>% map(., ~tsfeatures(.x[["Value"]], functions))