我编写了一个函数,它返回一个包含数字(odchylka.sr)和ggplot对象(ggpl)的列表
model.ARIMA.RF.fct <- function (l.obs.pomin) {
...
wynik.lst <- list (odchylka.sr, ggpl)
return(wynik.lst)
}
我根据
将结果保存在数据框中ARIMA.RF.cwu.wyniki <- data.frame(
l.obs.pomin = c(52, 69, 136, 217)
) %>%
mutate(
out = pmap(list (l.obs.pomin), model.ARIMA.RF.fct)
)
收到了
我希望 odchylka.sr 成为“out”列之前的单独列。
我无法完成这项任务。
我使用 pmap 因为我的目标函数有 3 个参数
function_that_returns_lists <- function(x){
list(thing_1 = x+1,
thing_2 = x^2)
}
df1 <- data.frame(
l.obs.pomin = c(52, 69, 136, 217)
) %>%
mutate(
out = pmap_df(list (l.obs.pomin), function_that_returns_lists) # pmap_df so out is more conveniently structured
) |> unnest(out) # easily seperate out by its columns into the dataset