lets say I have this list:
values <- list(2, 8, 3, 21, 54, 2, 43, 31)
countries <- list('US', 'UK', 'China', 'US', 'Russia', 'UK', 'US', 'China')
names(values) <- countries
Then, values looks like:('US' = 2, 'UK' = 8, 'China' = 3, 'US' = 21, 'Russia' = 54, 'UK' = 2, 'US' = 43, 'China' = 31)
Is there a built-in function in R or some short way to add the values of the duplicates?
Meaning, to make values become: ('UK' = 10, 'China' = 34, 'Russia' = 54, 'US' = 66)
(The order doesn't matter though)