[R] how to use a function in aggregate which accepts matrix and outputs matrix?

From: zhihuali <lzhtom_at_hotmail.com>
Date: Thu, 17 Apr 2008 19:00:56 +0000

Dear netters, suppose I have a matrix X [1,] 'c1' 'r6' '150'[2,] 'c1' 'r4' '70'[3,] 'c1' 'r2' '20'[4,] 'c1' 'r5' '90'[5,] 'c2' 'r2' '20'[6,] 'c3' 'r1' '10'I want to apply some funciton to groups of rows by the first column.If the function is just to calculate the average X[,3], it will be easy: aggregate(as.numeric(X[,3]),by=list(X[,1]),mean)But the function I want to use is more complicated. It will take as input a matrix(X[rows in the same group,c(2,3)], do some computation, and output another matrixwith the dimension (y,3), where y depends on the input. And I'd like the resultto be a rbind of each of the subset outputs. aggregate can not do that because the function is supposed to take vectors and output scalars.How can I apply the complicated function to groups of a matrix? Thanks! Zhihua Li

Windows Live Photo gallery 数码相机的超级伴侣,轻松管理和编辑照片,还能制作全景美图!

        [[alternative HTML version deleted]]

R-help_at_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. Received on Thu 17 Apr 2008 - 19:04:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Apr 2008 - 20:31:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive