Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-07 Thread Robin Hankin
One can always use the often-overlooked sweep(): a - matrix(2:7,2,3) b - matrix(1:2,2,1) sweep(a,1,b) [,1] [,2] [,3] [1,]135 [2,]135 best rksh On 6 Mar 2006, at 23:10, Michael wrote: Hi all, I want to substract vector B from A's each column... how

Re: [R] is there a way to let R do smart matrix-vector operation

2006-03-07 Thread Ted Harding
On 06-Mar-06 Michael wrote: Hi all, I want to substract vector B from A's each column... how can R do that smartly without a loop? A=matrix(c(2:7), 2, 3) A [,1] [,2] [,3] [1,]246 [2,]357 B=matrix(c(1, 2), 2, 1) B [,1] [1,]1 [2,]2 A-B

[R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Michael
Hi all, I want to substract vector B from A's each column... how can R do that smartly without a loop? A=matrix(c(2:7), 2, 3) A [,1] [,2] [,3] [1,]246 [2,]357 B=matrix(c(1, 2), 2, 1) B [,1] [1,]1 [2,]2 A-B Error in A - B : non-conformable arrays

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Marc Schwartz (via MN)
On Mon, 2006-03-06 at 15:10 -0800, Michael wrote: Hi all, I want to substract vector B from A's each column... how can R do that smartly without a loop? A=matrix(c(2:7), 2, 3) A [,1] [,2] [,3] [1,]246 [2,]357 B=matrix(c(1, 2), 2, 1) B [,1] [1,]

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Liaw, Andy
It's rarely necessary to have a vector in matrix form. In this case, it actually make things harder. If B had been a vector, you would have gotten: A=matrix(c(2:7), 2, 3) B=matrix(c(1, 2), 2, 1) A - as.vector(B) [,1] [,2] [,3] [1,]135 [2,]135 Andy From: Michael

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Berton Gunter
, March 06, 2006 3:11 PM To: R-help@stat.math.ethz.ch Subject: [R] is there a way to let R do smart matrix-vector operation? Hi all, I want to substract vector B from A's each column... how can R do that smartly without a loop? A=matrix(c(2:7), 2, 3) A [,1] [,2] [,3] [1,]2

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Anders Nielsen
Hi Michael, Try: A-as.vector(B) Cheers, Anders. On Monday 06 March 2006 01:10 pm, Michael wrote: Hi all, I want to substract vector B from A's each column... how can R do that smartly without a loop? A=matrix(c(2:7), 2, 3) A [,1] [,2] [,3] [1,]246 [2,]3

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Gabor Grothendieck
The following are nearly identical to what others have already written but just in case: A - c(B) or A - B[,1] or if B were already a vector, b, in the first place, rather than a matrix: b - 1:2 A - b On 3/6/06, Michael [EMAIL PROTECTED] wrote: Hi all, I want to substract vector B from

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Michael
Does R have a similarly smart division? I've tried hard on: A/as.vector(as.matrix(ddLen)) Error in A/as.vector(as.matrix(ddLen)) : non-numeric argument to binary operator but failed... Here my A is 10x10 matrix, and ddLen is a length-10 list of single numbers. On 3/6/06, Gabor Grothendieck

Re: [R] is there a way to let R do smart matrix-vector operation?

2006-03-06 Thread Daniel Nordlund
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Sent: Monday, March 06, 2006 5:56 PM To: Gabor Grothendieck Cc: R-help@stat.math.ethz.ch Subject: Re: [R] is there a way to let R do smart matrix-vector operation? Does R have a similarly