0

In R, if two vectors are of unequal length, the shorter one will be recycled in order to match the longer vector. For example, the following vectors ‘a’ and ‘b’ have unequal (different) lengths

> a = c(10, 20, 30)
> b = c(1, 2, 3, 4, 5, 6, 7, 8, 9)
> a + b

their sum is computed by recycling values of the shorter vector ‘a’.
[1] 11 22 33 14 25 36 17 28 39

And I wondered, why the shorter vector ‘a’ should be recycled? Why not just leave the extra values (4, 5, 6, 7, 8, 9) in the longer vector untouched by default?

Otherwise is it better to have another function that could add vectors without recycling?

Changed status to publish