[R] Sum vectors and numbers

guox at ucalgary.ca guox at ucalgary.ca
Wed Jul 7 17:35:03 CEST 2010


We want to sum many vectors and numbers together as a vector if there is
at least one vector in the arguments.
For example, 1 + c(2,3) = c(3,4).
Since we are not sure arguments to sum, we are using sum function:
sum(v1,v2,...,n1,n2,..).
The problem is that sum returns the sum of all the values present in its
arguments:
sum(1,c(2,3))=6
sum(1,2,3)=6
We do not want to turn sum(v1,v2,...,n1,n2,..) to v1+v2+...+n1+n2+...
So do you know easy way to sum vectors (v1,v2,...) and numbers (n1,n2,...)
as a vector without using v1+v2+...+n1+n2+...? Thanks,

-james



More information about the R-help mailing list