nested_numeric <- model_table %>%
group_by(ano_fiscal) %>%
select(-c("ano_estudo", "payout", "div_ratio","ebitda", "name.company",
"alavancagem","div_pl", "div_liq", "div_total")) %>%
nest()
nested_numeric
# A tibble: 7 x 2
# Groups: ano_fiscal [7]
ano_fiscal data
<dbl> <list>
1 2012 <tibble [34 x 10]>
2 2013 <tibble [35 x 10]>
3 2014 <tibble [35 x 10]>
4 2015 <tibble [35 x 10]>
5 2016 <tibble [35 x 10]>
6 2017 <tibble [35 x 10]>
7 2018 <tibble [35 x 10]>
df_ipca$idx
[1] 0.9652515 0.9741318 0.9817300 0.9911546 0.9941281 0.9985022 1.0000000
名为“数据”的列表列由数字变量组成。我想将它们相乘以获得通货紧缩指数。(又名通货膨胀调整)
这很好用
map2_df(nested_numeric$data, df_ipca$idx, ~ .x * .y)
甚至
map2(nested_numeric$data, df_ipca$idx, ~ .x * .y)
但我正在尝试使用此操作的结果创建一个名为“adjusted_data”的新列表列:
nested_numeric <- model_table %>%
group_by(ano_fiscal) %>%
select(-c("ano_estudo", "payout", "div_ratio","ebitda", "name.company",
"alavancagem","div_pl", "div_liq", "div_total")) %>%
nest() %>%
mutate( adjusted_data = data %>% {
map2(., df_ipca$idx, ~ .x * .y)})
给我这个错误:
Error: Column `adjusted_data` must be length 1 (the group size), not 7
我希望我的问题足够清楚,因为我正在尝试根据通货膨胀调整数据框,其值按年嵌套。我认为在 mutate 中使用 map2 就足够了......我已经尝试了所有方法,但无法弄清楚我做错了什么。我在这里读过关于 map2 中管道的类似问题,但仍然......
请帮忙:)谢谢!