Say that I have this data frame:
1 2 3 4 100 8 12 5 14 99 1 6 4 3 98 2 5 4 11 97 5 3 7 2
Another solution using bgoldst's definition of df1 and df2
df1
df2
sapply(unique(c(as.matrix(df2))),function(x) sum(df1[df2==x]))
Gives
#A B C D E F G #8 13 13 28 10 18 2
(Not quite the format that you wanted, but maybe it's ok...)