[R] Why does aggregate fail?
James Rome
jamesrome at gmail.com
Sun Feb 7 19:08:55 CET 2010
I am trying to get hourly totals, given 15-minute bins.
s = seq(0, 95, 1)
s = floor(s/4) # 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 . . .
> s
[1] 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5
5 5 6
[26] 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11
11 12 12
[51] 12 12 13 13 13 13 14 14 14 14 15 15 15 15 16 16 16 16 17 17 17 17
18 18 18
[76] 18 19 19 19 19 20 20 20 20 21 21 21 21 22 22 22 22 23 23 23 23
> mode(d)
[1] "list"
> d
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26
Sunday 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0
0 0
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
49 50
Sunday 0 0 0 0 0 5 5 5 0 0 0 0 0 0 0 6 0 3 1 0 1
6 8 9
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74
Sunday 7 9 10 5 0 1 0 1 1 1 0 0 0 1 0 0 7 10 9 9 11
11 8 8
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
Sunday 10 7 6 7 8 7 4 4 6 5 5 5 5 0 0 0 1 6 2 3 0
> x = aggregate(d, by=list(s), FUN="sum")
Error in FUN(X[[1L]], ...) : arguments must have same length
> length(s)
[1] 96
> length(d)
[1] 96
What am I doing wrong?
Thanks in advance list,
Jim Rome
More information about the R-help
mailing list