You should be using mapply()
instead of sapply()
:
mapply(bear.correction,x,y)
Why? Your sapply()
applies bear.correction()
to each entry of x
... but giving it the entire y
vector as a second argument in each case, and so bear.correction()
only looks at the first entry in y
in all four cases. To "walk along" multiple entries in multiple vectors (or other data structures), use mapply()
.