I am trying to extract data from the World Bank and import it into RStudio for a regression analysis. The data can be found here and as you can see, the online table shows the latest available data.
However, the downloadable CSV/excel files have columns for every year between 1960 and 2021.
What I want to do now is to create a new data frame where I have the latest data for each of the countries – basically, I want to recreate what can be found on World Bank's site online already.
I have googled around for quite a while but I could not find anything that fits my specific problem.
What I did find were some ways on how to select the newest data from a data frame, but all these solutions required a date column, which my dataset does not have – I have columns for (1960:2021).
Example: Take this data frame:
df <- data.frame(c(1:10),c(1:4,NA))
df
c.1.10. c.1.4..NA.
1 1 1
2 2 2
3 3 3
4 4 4
5 5 NA
6 6 1
7 7 2
8 8 3
9 9 4
10 10 NA
What I want to do is replace the NA-values with the values from the previous column, so with the 5 and the 10. How can I do that?
I'm thankful for any help!