I have this dataset Overview of my dataset. I need to take the SDI variable and make it a constant, so that the value from the lowest year is displayed on every entry for every country.
ex.
**Current:** **What I need:**
|Angola, 2005 -> SDI = 2.0 | Angola, 2005 -> SDI = 2.0
|Angola, 2013 -> SDI = 3.0 | Angola, 2013 -> SDI = 2.0
|Angola, 2017 -> SDI = 2.5 | Angola, 2017 -> SDI = 2.0
|Argentina, 2005 -> SDI = 8.0 | Argentina, 2005 -> SDI = 8.0
|Argentina, 2013 -> SDI = 7.0 | Argentina, 2013 -> SDI = 8.0
|Argentina, 2017 -> SDI = 7.5 | Argentina, 2017 -> SDI = 8.0
So whatever the lowest year for that country is that is the SDI value that needs to become constant and be displayed regardless of the years to come. (if that makes sense)
My second dilemma is that i need to take the ODA variable and divide it by the population for each country. I'm wondering if there is a faster way to do this then by doing it individually for each country.
So for Afghanistan 2013 the ODA is 5239070000 / AFG_population and Angola 2005 the ODA is 1667990000 / AGO_population
and then continuing this for all the countries, as i need to derive their per capita result.
Country = c("Afghanistan", "Algeria","Angola","Argentina","Armenia",
"Bangladesh","Belarus","Benin","Bhutan","Brazil")
year = c("2013", "2017", "2005", "2009", "2005",
"2009", "2005", "2005", "2009", "2005" )
ODA = c("5239070000", "2186920000", "1667990000","2102860000",
"215700000","1943200000","141020000",
"379850000","163570000","21630120000")
df = data.frame(Country, year, ODA)
(Short version of my dataset)
I have tried creating subsets and looking at different functions. But I'm completely stumped and not even sure how or where I should look anymore.. :(
If anyone can help me with this then i would be forever grateful!