>>>>> "VZ" == Valerie Zartarian <VZARTARIAN@usgs.gov> writes:
VZ> Hi, My original dataframe VZ.df looks like:
...
VZ> I want to aggregate V5 over common rows sequentially as follows:
...
VZ> Any ideas on how to do it without a for loop?
I'm not sure that it is the most efficient solution but the gapply
function in the nlme 3.0 library (available at
http://nlme.stat.wisc.edu/Beta/) can do this by regarding the V1, V2,
V3, and V4 factors as being nested classification factors.
S> foo
V1 V2 V3 V4 V5
1 a b d g 5
2 a b d g 5
3 a b d g 5
4 a b d g 5
5 a c e g 5
6 a c e h 5
7 a c e g 5
8 a c e g 5
9 a c e h 5
10 a c e h 5
11 a c f g 5
12 a c f g 5
S> gapply( foo, form = ~ V1/V2/V3/V4, FUN = function(x) sum(x$V5) )
a/b/d/g a/c/e/g a/c/e/h a/c/f/g
20 15 15 10
Note: You need the 3.0 version of the nlme library to do this. You
would have to pick up the files from the above location and install them.
That may be more trouble than it is worth for this application.
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|