1

I know that there is a few threads (1, 2) already about it and I have read them, but I still do not find my problem.

The error seems to occur "randomly", even though I am sure it is not, but I can just not figure out, when.

Therefore I cannot really provide a minimal example, as I could not find a "pattern" yet.

But basically I always use

hourly <- ddply(set, c("Date", "Hour"), summarise, avg = mean(Value))

which leads to

Error: 'names' attribute [11] must be the same length as the vector [1]

traceback() provides

> traceback()
6: stop(list(message = "Attribut 'names' [11] muss dieselbe Länge haben wie der Vektor [1]", 
       call = NULL, cppstack = NULL))
5: .Call("plyr_loop_apply", PACKAGE = "plyr", n, f)
4: loop_apply(n, do.ply)
3: llply(.data = .data, .fun = .fun, ..., .progress = .progress, 
       .inform = .inform, .parallel = .parallel, .paropts = .paropts)
2: ldply(.data = pieces, .fun = .fun, ..., .progress = .progress, 
       .inform = .inform, .parallel = .parallel, .paropts = .paropts)
1: ddply(set, c("Date", "Hour"), summarise, avg = mean(Value))

The str() of the dataframe:

> str(set)
'data.frame':   2155 obs. of  16 variables:
 $ T_Stamp : POSIXlt, format: "2013-06-18 09:01:00" "2013-06-18 09:02:00" "2013-06-18 09:03:00" ...
 $ Date    : Date, format: "2013-06-18" "2013-06-18" "2013-06-18" ...
 $ Time    : num  0.376 0.376 0.377 0.378 0.378 ...
 $ Year    : int  2013 2013 2013 2013 2013 2013 2013 2013 2013 2013 ...
 $ Month   : int  6 6 6 6 6 6 6 6 6 6 ...
 $ Day     : int  18 18 18 18 18 18 18 18 18 18 ...
 $ Hour    : int  9 9 9 9 9 9 9 9 9 9 ...
 $ Min     : int  1 2 3 4 5 6 7 8 9 10 ...
 $ Customer: chr  "1" "1" "1" "1" ...
 $ Property: chr  "1" "1" "1" "1" ...
 $ Serial  : Factor w/ 13 levels "000D6F00010B723F",..: 9 9 9 9 9 9 9 9 9 9 ...
 $ Sensor  : chr  "AirCon" "AirCon" "AirCon" "AirCon" ...
 $ ID      : Factor w/ 44 levels "300","301","302",..: 30 30 30 30 30 30 30 30 30 30 ...
 $ Unit    : chr  "Total Active Power" "Total Active Power" "Total Active Power" "Total Active   Power" ...
 $ Value   : num  68 68.2 68.2 67.7 68.5 ...
 $ Hourf   : Factor w/ 13 levels "9","10","11",..: 1 1 1 1 1 1 1 1 1 1 ...

Does anyone know about a common mistake one can do, when using ddply for summarising (as I do for calculating means)?

Community
  • 1
  • 1
schluk5
  • 177
  • 2
  • 13
  • Have you tried the solution in @c.gutierrez 's answer in the second link you provided? – konvas Oct 16 '14 at 15:43
  • 1
    My guess is you are creating the `Date` variable from the `Time` variable, which is currently `POSIXlt`. Convert `Time` to `POSIXct` before making `Date`. – aosmith Oct 16 '14 at 16:01
  • Thank you both of you! I tried converting the T_Stamp to POSIXct before, with no improvement. That is why I did not try it again. Now it works! I think I had another date variable included before, which was interfering with it.. – schluk5 Oct 17 '14 at 10:48

0 Answers0