let’s say I have a matrix like this:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 3 5 7 9 11 13 15 17
[2,] 2 4 6 8 10 12 14 16 18
I’m looking for an easy way to substract the 3rd column from the 1st and 2nd, then the 6th from the 4th and 5th, and so on.
Can I do this without a for-loop?
Thanks in advance,
zenzen.
This answer isn’t beautiful. It should really be made into a function for clarity, but:
no for loop! And the result is:
edit: here it is as a function