Using R:
I have a list of vectors with length n, that correspond to a vector of ids, also of length n. so there are m id's in each vector in the list. I also have a vector of values, length m:
L1 = c(1,65,23)
L2 = c(1,23,45)
L3 = c(45,23)
L4 = c(45,65)
V2 = list(L1,L2,L3,L4)
IDs = c(1, 23, 45, 65)
Values = c(400, 500, 100, 150)
dat = data.frame(IDs, Values)
I would like to subtract each value from the corresponding (by index) list. In a loop this would be something like:
testFun = function(dat){
y = list()
for (i in 1:nrow(dat)){
y[[i]] = dat$Value[i] - dat$Value[which(dat$IDs %in% V2[[i]])]
}
return(y)
}
testFun(dat)
Basically, this works, but does not scale well. Any help would be much appreciated! Thanks