Lookup GINI by year and country
With the data.table package, you can do a quick join and get the gini coefficient much easier. This solution is also vectorized, so you can call it with something like gini(2000:2004, 'USA') to get the gini coefficients for the USA for years 2000-2004. 

It is also good practice to include the data in your function call, so you don't use objects from the global environment within the function call. This function outputs the entire data.table, but you can also just use the gini coefficient as output, if you add [, GINI] at the end.  

gini &lt;- function(year, country, data = inequality){
  require(data.table)
  setkey(setDT(data), 'Code', 'Year')[J(Code = country, Year=year), 
                                        list(GINI = mean(as.numeric(Gini))), 
                                        by=list(Code, Year)]
}