I have looked pretty much everywhere and cannot find the answer to this; R equivalent of VLOOKUP on Excel. VLOOKUP allows me to look up for a specific value throughout a column and apply it to each row of my data frame.
In this case I want to find the country a particular city is in (from a database) and return the name of the country in a new column.
So I have this database:
countries <- c("UK", "US", "RUS")
cities <- c("LDN", "NY", "MOSC")
db <- cbind(countries, cities)
db
countries cities
[1,] "UK" "LDN"
[2,] "US" "NY"
[3,] "RUS" "MOSC"
And want to find the country those cities are in (replace NA) based on the db above:
df
countries cities
[1,] NA "LDN"
[2,] NA "NY"
[3,] NA "MOSC"
I have absolutely no idea how to go about this on R.