I have a data.table()
with the columns : city,month, year and gdp_per_capta. (actually I have 30 more columns)
My base is full fill from 2005 to 2018.
But, to the year 2019, the gdp_per_capta has NA.
I would like to put a value on it, this way: 2019 = (2018/2017) * 2018
How can I do it?
PS: How can I improve the title of this question?
Example of my data:
structure(list(city = c(110001L, 110001L, 110001L, 110001L,
110001L, 110001L, 110001L, 110001L, 110001L, 110001L, 110001L,
110001L, 110037L, 110037L, 110037L, 110037L, 110037L, 110037L,
110037L, 110037L, 110037L, 110037L, 110037L, 110037L, 110040L,
110040L, 110040L, 110040L, 110040L, 110040L, 110040L, 110040L,
110040L, 110040L, 110040L, 110040L), month = c("01", "04", "07",
"10", "02", "05", "08", "11", "03", "06", "09", "12", "01", "04",
"07", "10", "02", "05", "08", "11", "03", "06", "09", "12", "01",
"04", "07", "10", "02", "05", "08", "11", "03", "06", "09", "12"
), year = c(2017L, 2017L, 2017L, 2017L, 2018L, 2018L, 2018L, 2018L,
2019L, 2019L, 2019L, 2019L, 2017L, 2017L, 2017L, 2017L, 2018L,
2018L, 2018L, 2018L, 2019L, 2019L, 2019L, 2019L, 2017L, 2017L,
2017L, 2017L, 2018L, 2018L, 2018L, 2018L, 2019L, 2019L, 2019L,
2019L), gdp_per_capta = c(19081.43, 19081.43, 19081.43,
19081.43, 21552.47, 21552.47, 21552.47, 21552.47, NA, NA, NA,
NA, 23353.6, 23353.6, 23353.6, 23353.6, 21053.93, 21053.93, 21053.93,
21053.93, NA, NA, NA, NA, 14699.7, 14699.7, 14699.7, 14699.7,
15655.57, 15655.57, 15655.57, 15655.57, NA, NA, NA, NA)), row.names = c(NA,
-36L), class = c("data.table", "data.frame"))
Expected result: