Reputation: 10324
So the behavior of the following code:
x = c(1, 2, 3, 4, 5)
print(sum(x - 3))
But what is the behavior of using multiple vectors in a sum
?
For example:
print(sum(x - y - 3))
print(sum(x - y - z - 3))
Upvotes: 2
Views: 275
Reputation: 101343
For
sum(v1 - v2 - 3)
it is equivalent to
v <- v1 - v2
sum(v - 3)
where v
is a vector from the element-wise difference between v1
and v2
, and sum(v-3)
is the same as what you did to sum(vector - 3)
in your post.
If you have unequal lengths between multiple vectors, the recycling rule will be applied (see comment by @Waldi)
Upvotes: 3