Re: [R] data manipulation between vector and matrix

2012-12-05 Thread arun
z5. > >A.K. > > > > > > > > >From: C W >To: arun >Cc: R help ; Sarah Goslee >Sent: Wednesday, December 5, 2012 4:47 PM > >Subject: Re: [R] data manipulation between vector and matrix > > >Thanks for the

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread arun
ystem elapsed #  0.008   0.000   0.009 A.K. From: C W To: arun Cc: R help ; Sarah Goslee Sent: Wednesday, December 5, 2012 4:11 PM Subject: Re: [R] data manipulation between vector and matrix thanks, I knew about apply, but did not you you can put plu

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
0.008 0.000 0.009 > > > A.K. > > > > > > ________ > From: C W > To: arun > Cc: R help ; Sarah Goslee > Sent: Wednesday, December 5, 2012 4:11 PM > Subject: Re: [R] data manipulation between vector and matrix > > >

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread arun
HI, In addition to ?sweep(), you can use apply(-mat,1,`+`,x) #or library(plyr) aaply(-mat,1,"+",x) A.K. - Original Message - From: C W To: Sarah Goslee Cc: r-help Sent: Wednesday, December 5, 2012 1:51 PM Subject: Re: [R] data manipulation between vector and matr

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
aaply(-mat,1,"+",x) > > > A.K. > > > > > > > - Original Message - > From: C W > To: Sarah Goslee > Cc: r-help > Sent: Wednesday, December 5, 2012 1:51 PM > Subject: Re: [R] data manipulation between vector and matrix > > Thanks, Sarah. First time

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
Thanks, Sarah. First time heard about sweep(), it worked just the way I wanted. Mike On Wed, Dec 5, 2012 at 1:42 PM, Sarah Goslee wrote: > Hi, > > On Wed, Dec 5, 2012 at 1:30 PM, C W wrote: > > Dear list, > > I was curious how to subtract a vector from matrix? > > > > Say, I have > > > > mat <

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread Sarah Goslee
Hi, On Wed, Dec 5, 2012 at 1:30 PM, C W wrote: > Dear list, > I was curious how to subtract a vector from matrix? > > Say, I have > > mat <- matrix(1:40, nrow=20, ncol=2) > > x <-c(1,2) Thanks for the actual reproducible example. > I want, > > x-mat[1,] and x-mat[2,], and so on... Basically, su

Re: [R] data manipulation between vector and matrix

2012-12-05 Thread C W
The only solution I found was x-t(mu) Is there a better way? Mike On Wed, Dec 5, 2012 at 1:30 PM, C W wrote: > Dear list, > I was curious how to subtract a vector from matrix? > > Say, I have > > mat <- matrix(1:40, nrow=20, ncol=2) > > x <-c(1,2) > > I want, > > x-mat[1,] and x-mat[2,], and so

[R] data manipulation between vector and matrix

2012-12-05 Thread C W
Dear list, I was curious how to subtract a vector from matrix? Say, I have mat <- matrix(1:40, nrow=20, ncol=2) x <-c(1,2) I want, x-mat[1,] and x-mat[2,], and so on... Basically, subtract column elements of x against column elements in mat. But x-mat won't do it. Thanks, Mike [[al