Brilliant! > t1=matrix(1:15,5,3) > t1 [,1] [,2] [,3] [1,] 1 6 11 [2,] 2 7 12 [3,] 3 8 13 [4,] 4 9 14 [5,] 5 10 15 > t2=1:5 > t2 [1] 1 2 3 4 5
> sweep(t1, 1, t2) [,1] [,2] [,3] [1,] 0 5 10 [2,] 0 5 10 [3,] 0 5 10 [4,] 0 5 10 [5,] 0 5 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) > > > 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 > > > > Thanks in advance. > > > > _________________________________________________________________ > > > > > > 08 > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O _________________________________________________________________ Need to know the score, the latest news, or you need your Hotmail®-get your "fix". [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.