I have a lot of data to work on, and to make things more efficient I would like to come up with a code that will allow me to assign a regional code to an article per the country of origin of its author.
In other words, I have the following:
country$author_country
MEX
COL
TUN
GBR
USA
BRA
etc.
I have created a column 'author_region' filled with NAs. I want to assign a region code to everyone of the author_country values.
Instead of doing it by hand, for instance something like if(country$author_country == MEX){country$author_region == 1}
,
I was hoping there is a way to create an object that would allow me to list all the countries from a region, and then assign a value to my author_region column based on whether or not author_country matches the content of this object. I thought about doing it like this:
LatAm <- list('COL', 'MEX', 'BRA')
for (i in country$author_country) if (country$author_country == LatAm)
{country$author_region[i] <- 1}
I know this looks wrong and it obviously does not work, but I couldn't find a solution to this issue. Could you help me please?
Thank you!!