[R] Grouping and Averaging in Table

From: Prasanna BALAPRAKASH <prasannaprakash_at_gmail.com>
Date: Sat 18 Feb 2006 - 02:28:46 EST


Dear Rs

I have a single table with three columns in the following form:

1	100	150
1	45	32
1	99	100
2	150	33
2	22	87
2	71	31

....
....
1000	64	32
1	100	150
1	45	32
1	99	100
2	22	89
2	31	44
2	88	11

....
....
1200	64	32
1	100	150
1	45	32
1	99	100
2	150	33
2	22	87
2	71	31

...
...

1100 31 34

Totally 1000+1200+1100 rows. Now, I need to group by first column and average then second and third column to get a table as follows as follows:

1 Avg. of all second col. values whose first col value is 1 Avg. of all third col. values whose first col value is 1 2 Avg. of all second col. values whose first col value is 2 Avg. of all third col. values whose first col value is 2
..
..

1200 Avg. of all second col. values whose first col value is 1200 Avg. of all third col. values whose first col value is 1200

Right now, I have a dirty implementation with a lot of "for" loops and "if" conditions. However, I am looking for some built in functions and lib. to make the code faster and easier.

Thanks
Prasanna



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Feb 18 02:14:37 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:34 EST