[R] Why does aggregate fail?
James Rome
jamesrome at gmail.com
Sun Feb 7 19:29:42 CET 2010
> dput(d)
structure(list(`0` = 0, `1` = 1, `2` = 0, `3` = 0, `4` = 0, `5` = 0,
`6` = 0, `7` = 0, `8` = 0, `9` = 0, `10` = 0, `11` = 0, `12` = 0,
`13` = 0, `14` = 0, `15` = 0, `16` = 0, `17` = 2, `18` = 0,
`19` = 0, `20` = 0, `21` = 0, `22` = 0, `23` = 0, `24` = 0,
`25` = 0, `26` = 0, `27` = 0, `28` = 0, `29` = 0, `30` = 0,
`31` = 0, `32` = 5, `33` = 5, `34` = 5, `35` = 0, `36` = 0,
`37` = 0, `38` = 0, `39` = 0, `40` = 0, `41` = 0, `42` = 6,
`43` = 0, `44` = 3, `45` = 1, `46` = 0, `47` = 1, `48` = 6,
`49` = 8, `50` = 9, `51` = 7, `52` = 9, `53` = 10, `54` = 5,
`55` = 0, `56` = 1, `57` = 0, `58` = 1, `59` = 1, `60` = 1,
`61` = 0, `62` = 0, `63` = 0, `64` = 1, `65` = 0, `66` = 0,
`67` = 7, `68` = 10, `69` = 9, `70` = 9, `71` = 11, `72` = 11,
`73` = 8, `74` = 8, `75` = 10, `76` = 7, `77` = 6, `78` = 7,
`79` = 8, `80` = 7, `81` = 4, `82` = 4, `83` = 6, `84` = 5,
`85` = 5, `86` = 5, `87` = 5, `88` = 0, `89` = 0, `90` = 0,
`91` = 1, `92` = 6, `93` = 2, `94` = 3, `95` = 0), .Names = c("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", "27", "28", "29", "30", "31", "32", "33", "34",
"35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45",
"46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56",
"57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67",
"68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78",
"79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
"90", "91", "92", "93", "94", "95"), row.names = "Sunday", class =
"data.frame")
On 2/7/2010 1:27 PM, David Winsemius wrote:
On Feb 7, 2010, at 1:08 PM, James Rome wrote:
> 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
I don't know what sort of error is occurring. You have not created a
posting that easily lets us see what sort of object "d" really is. (And
it is not being display as though it were a simple list.)
dput(d) would have allowed us to see what sort of attributes it has.
Your code works if one strips out the data and puts it into a vector.
> s = seq(0, 95, 1)
> s = floor(s/4)
> d <- scan()
1: 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
26: 0 0
28: 0 0 0 0 0 5 5 5 0 0 0 0 0 0 0 6 0 3 1 0 1
49: 6 8 9
52: 7 9 10 5 0 1 0 1 1 1 0 0 0 1 0 0 7 10 9 9 11
73: 11 8 8
76: 10 7 6 7 8 7 4 4 6 5 5 5 5 0 0 0 1 6 2 3 0
97:
Read 96 items
> x = aggregate(d, by=list(s), FUN="sum")
> x
Group.1 x
1 0 1
2 1 0
3 2 0
4 3 0
5 4 2
6 5 0
7 6 0
8 7 0
9 8 15
10 9 0
11 10 6
12 11 5
13 12 30
14 13 24
15 14 3
16 15 1
17 16 8
18 17 39
19 18 37
20 19 28
21 20 21
22 21 20
23 22 1
24 23 11
>> length(s)
> [1] 96
>> length(d)
> [1] 96
>
> What am I doing wrong?
>
> Thanks in advance list,
> Jim Rome
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list