Luc, Eik, Jorge, thanks to all of you! Nice to see how many different solutions there are for the same problem. :)
Best Henning Am 07.04.2009 um 22:25 schrieb Jorge Ivan Velez: > > Dear Hans, > > Try also: > > x <- structure(c(2, 1, 2, 1, 3, 2, 4, 1, 4, 3, 4, 3, 5, 2, 5, 1, 6, > 1), .Dim = c(2L, 9L)) > tapply(x[2,],x[1,],sum) > #2 3 4 5 6 > #2 2 7 3 1 > > HTH, > > Jorge > > > On Tue, Apr 7, 2009 at 11:06 AM, Hans-Henning Gabriel > <hanshenning.gabr...@gmail.com > > wrote: > Hi, > > my problem is as follows: > > I have a matrix of two rows like this: > > 2 2 3 4 4 4 5 5 6 > 1 1 2 1 3 3 2 1 1 > > Can I apply something like "group by" in sql? What I want to achieve > is the some of second row for each unique entry of first row: > > 2 -> 2 (=1+1) > 3 -> 2 > 4 -> 7 (=1+3+3) > 5 -> 3 (=2+1) > 6 -> 1 > > Thanks!! > Henning > > ______________________________________________ > 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. > [[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.