Re: [R] Element-by-element operation (adding)

2016-05-23 Thread peter dalgaard
> On 23 May 2016, at 07:44 , Peter Langfelder > wrote: > > or > > t(apply(v, 1, `+`, b)) Or, as you're messing with transposes anyways, use the fact that the column-wise counterpart is automagically handled by recycling: t(t(v)+b) Or, look Ma, no transposes v + rep(b, each=nrow(v)) (_al

Re: [R] Element-by-element operation (adding)

2016-05-22 Thread Peter Langfelder
Two solutions... v + matrix(b, nrow(v), ncol(v), byrow = TRUE) or t(apply(v, 1, `+`, b)) Peter On Sun, May 22, 2016 at 10:39 PM, Steven Yen wrote: > Hi all, need help below. Thank you. > > > # Matrix v is 5 x 3 > > # Vector b is of length 3 > > # I like to add b[1] to all element in v[,1]