adding two vectors or lists in R -
i have 2 list or vectors following in r:
vector 1 d1 d2 d3 d4 2 0.75 1 0.25 0 vector 2 [1] "1" "3"
i need add values of vector 1 considering values of vector2, mean in example add values of d1 plus d3 because vector 2 has indexes. considering in using loop traverse vector 2 , adding values of vector1, not other more direct way perform operation? remember can used converting indexes in t, f values, frankly quite don't remember.
try:
sum(vector1[match(vector2, gsub("d", "", names(vector1)))]) [1] 1
Comments
Post a Comment