I am creating an R function that needs to adjust the income values for specific years to the 2018 USD value. The previous years are 1972, 1980, 1990, 2000, and 2010. I have a variable in my dataset that is called "year" and a variable called "income".
In the function, I need to use loops to cycle through the years and adjust the income value for each observation within each year to the 2018 USD value. I have the conversion rates for each year, but I am not sure how to create a loop that cycles through each year and does the specific conversion for each year.
This is my first time creating a function and my first time really using loops. I tried to do this but it is not producing any values in my dataframe:
incomeadj=NA
uslop2 <- cbind(uslop, incomeadj)
adjust_income <- function(uslop2){
if (uslop2$year == 1972){
uslop2$incomeadj <- uslop2$income*(251.23/41.8)
} else {NA}
}
uslop2$incomeadj
I feel like I can eventually grasp what I need to do, but I am struggling right now. Any help is greatly appreciated.