I have this matrix:
> y
[,1] [,2] [,3] [,4]
[1,] 1 8 36 180
[2,] 5 24 21 32
[3,] 9 40 6 48
[4,] 13 56 45 180
[5,] 17 72 117 28
and this vector:
> x
[1] 10 25 34 41 59
I should SUM the elements of the row and then subtract the result with the respective value on the x ve开发者_开发技巧ctor.
Example:
10 - (1 + 8 + 36 + 180)
25 - (5 + 24 + 21 + 32)
34 - (9 + 40 + 6 + 48)
41 - (13 + 56 + 45 + 180)
59 - (17 + 72 + 117 + 28)
How can I create a vector with the results of those computations?
Thanks
This should work:
x-rowSums(y)
精彩评论