I have two list or vectors as the following in R:
vector 1
d1 d2 d3 d4
2 0.75 1 0.25 0
vector 2
[1] "1" "3"
I need to add the values of vector 1 considering the values of vector2, I mean in my example to add the values of d1 plus d3 because vector 2 has those indexes. I was considering in using a for loop to traverse vector 2 and the adding the values of vector1, but is not other more direct way to perform this operation? I remember that it can be used by converting the indexes in T, F values, but frankly I quite don't remember.