Re: [R] elegant way to minus on each row of a matrix

2008-03-02 Thread Bo Zhou
CTED] > To: [EMAIL PROTECTED] > CC: r-help@r-project.org > Subject: Re: [R] elegant way to minus on each row of a matrix > > try this: > > mat <- matrix(1:9, 3, 3, TRUE) > dat <- as.data.frame(mat) > vec <- 1:3 > > result.mat <- mat - vec > re

Re: [R] elegant way to minus on each row of a matrix

2008-03-02 Thread Bo Zhou
10 [4,]05 10 [5,]05 10 > Date: Sun, 2 Mar 2008 14:56:22 -0300 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] elegant way to minus on each row of a matrix > CC: r-help@r-project.org > > Try this: > > sweep(mat, 1, vec) >

Re: [R] elegant way to minus on each row of a matrix

2008-03-02 Thread Bo Zhou
t2 [1] 1 2 3 4 5 > apply(t1,2, function(x) x - t2) [,1] [,2] [,3] [1,]05 10 [2,]05 10 [3,]05 10 [4,]05 10 [5,]05 10 > > Date: Sun, 2 Mar 2008 12:51:53 -0500 > From: [EMAIL PROTECTED] > Subject: RE: [R] elegant way to mi

Re: [R] elegant way to minus on each row of a matrix

2008-03-02 Thread Dimitris Rizopoulos
try this: mat <- matrix(1:9, 3, 3, TRUE) dat <- as.data.frame(mat) vec <- 1:3 result.mat <- mat - vec result.dat <- dat - vec result.mat result.dat I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Ka

Re: [R] elegant way to minus on each row of a matrix

2008-03-02 Thread Henrique Dallazuanna
Try this: sweep(mat, 1, vec) On 02/03/2008, Bo Zhou <[EMAIL PROTECTED]> wrote: > > How to do this in an elegant way formatrix/data frame/zoo? > > mat= > 1 2 3 > 4 5 6 > 7 8 9 > > vector= > 1 > 2 > 3 > > > result= > 0 1 2 > 2 3 4 > 4 5 6 > > ie > 1-1 2-1 3-1 > 4-2 5-2 6-2 > 7-3 8-3 9-3 > >

[R] elegant way to minus on each row of a matrix

2008-03-02 Thread Bo Zhou
How to do this in an elegant way formatrix/data frame/zoo? mat= 1 2 3 4 5 6 7 8 9 vector= 1 2 3 result= 0 1 2 2 3 4 4 5 6 ie 1-1 2-1 3-1 4-2 5-2 6-2 7-3 8-3 9-3 Thanks in advance. _ 08 [[alternative HTML version