1
I have a data.table()
with the following columns: municipality, year and pib_per_capta. (I actually have 30 more columns, but for example I think this is enough)
The base is fully filled from 2005 to 2018. However, for the year 2019 pib_per_capta is as IN.
I would like to assign value to it in the following way: get the variation rate of 2017 and 2018, and multiply by the value of 2018.
How would that look?
Note: 2019 = (2018/2017) * 2018 Note: If you know how to improve the title of the question, just talk
Data example:
structure(list(municipio = c(110001L, 110001L, 110001L, 110037L,
110037L, 110037L, 110040L, 110040L, 110040L, 110034L, 110034L,
110034L), ano = c(2017L, 2018L, 2019L, 2017L, 2018L, 2019L, 2017L,
2018L, 2019L, 2017L, 2018L, 2019L), pib_per_capta = c(19081.43,
21552.47, NA, 23353.6, 21053.93, NA, 14699.7, 15655.57, NA, 15062.51,
17423.49, NA)), row.names = c(NA, -12L), class = c("data.table",
"data.frame"))