[R] aggregating columns in a data frame in different ways

2006-04-28 Thread kavaumail-r
I would like to use aggregate() to combine statistics for several days in a data frame. My data frame looks similar to this: datetype count value 1 2006-04-01 A 10 99.6 2 2006-04-01 B 4 33.2 3 2006-04-02 A 22 43.2 4 2006-04-02 B 8 44.9 5

Re: [R] aggregating columns in a data frame in different ways

2006-04-28 Thread jim holtman
Does this do what you want? x date type count value 1 2006-04-01A10 99.6 2 2006-04-01B 4 33.2 3 2006-04-02A22 43.2 4 2006-04-02B 8 44.9 5 2006-04-03A12 12.4 6 2006-04-03B14 18.5 y - lapply(split(1:nrow(x), x$type), function(.ind){ +

Re: [R] aggregating columns in a data frame in different ways

2006-04-28 Thread Gabor Grothendieck
Here are three possibilities: 1. aggregate on the columns that you want to sum and aggregate on the columns that you want to average and then merge them: By - A[, 2, drop = FALSE] merge(aggregate(A[, 3, drop = FALSE], By, sum), aggregate(A[, 4, drop = FALSE], By, mean)) 2. use by: f -