On Thu, Mar 19, 2009 at 8:40 PM, jim holtman wrote:
> Try this technique. I use it with large data objects since it is
> sometime faster, and uses less memory, by using indices:
>
> x <- read.table(textConnection(" v1 v2 n1 n2
> 1 a a1 1 21
> 2 a a1 2 22
> 3 a a1 3 23
> 4 a a2 4 24
>
Try this technique. I use it with large data objects since it is
sometime faster, and uses less memory, by using indices:
x <- read.table(textConnection(" v1 v2 n1 n2
1 a a1 1 21
2 a a1 2 22
3 a a1 3 23
4 a a2 4 24
5 a a3 5 25
6 b b1 6 26
7 b b1 7 27
8 b b2 8 28
9 b b2
Here are two solutions:
> aggregate(testDF[c("n1", "n2")], testDF[c("v1", "v2")], sum)
v1 v2 n1 n2
1 a a1 6 66
2 a a2 4 24
3 a a3 5 25
4 b b1 13 53
5 b b2 27 87
6 c c1 11 31
7 c c2 39 99
8 c c3 15 35
9 d d1 16 36
10 d d2 17 37
11 d d3 18 38
12 d d4 39 79
> library(sqldf
Hi,
I think I found the solution.
Using doBy library, I got:
testDF.result2 <- summaryBy(n1+n2 ~ v1+v2, data = testDF, FUN=sum)
> testDF.result2
v1 v2 n1.sum n2.sum
1 a a1 6 66
2 a a2 4 24
3 a a3 5 25
4 b b1 13 53
5 b b2 27 87
6 c c1
Hi,
I am trying to aggregate the sum of my test data.frame as follow:
testDF <- data.frame(v1 = c("a", "a", "a", "a", "a", "b", "b", "b", "b",
"b", "c", "c", "c", "c", "c", "d", "d", "d", "d", "d"),
v2 = c("a1", "a1", "a1", "a2", "a3", "b1", "b1", "b2",
"b2", "b2", "c1", "c2"
5 matches
Mail list logo