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
The list-column named "data" consists of numeric variables. I want to multiply them for a deflator index. (a.k.a. adjusting for inflation)
this works fine
map2_df(nested_numeric$data, df_ipca$idx, ~ .x * .y)
or even
map2(nested_numeric$data, df_ipca$idx, ~ .x * .y)
but I'm trying to create a new list-column named "adjusted_data" with the result of this operation:
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)})
Gives me this error:
Error: Column `adjusted_data` must be length 1 (the group size), not 7
I hope my problem is clear enough because I'm trying to adjust for inflation a data frame with values nested by years. I thought that going for map2 within a mutate would be enough... I've tried everything and couldn't figure it what I'm doing wrong. I've read similar questions with pipes within map2 here, but still...
Please help :) Thank you!
mutate(adjuated_data = map2(data, df_ipca$idx, ~ .x * .y))
– akrun