mlandistest / code

2 stars 0 forks source link

Vector arithmetics [sf#25] #37

Open mlandis opened 10 years ago

mlandis commented 10 years ago

Reported by hoehna on 2013-11-11 10:12 UTC We need component-wise multiplication of vectors. Similarly, component- or element-wise subtraction, multiplication etc. What should these functions be called?

mlandis commented 10 years ago

Commented by michaellandis on 2014-07-01 22:51 UTC R handles this by looping over the elements in the smaller vector (or scalar) and adding them in order to the larger vector. e.g. For addition, if vectors are equal in size, elements of matching index are summed and returned. If one argument is a scalar, then the elements in the other argument (vector) are added to the scalar and returned.

c(1,2)+c(2,4) [1] 3 6

1+c(2,4) [1] 3 5

c(1,2)+c(2,3,4) [1] 3 5 5 Warning message: In c(1, 2) + c(2, 3, 4) : longer object length is not a multiple of shorter object length