1

I am trying to calculate the hourly averages (January 2014) of a dataset using timeAverage() function. The command looks like follows:

AQHr <- timeAverage(my_data, avg.time = "hour", data.thresh = 0,
                       statistic = "mean", percentile = NA,
                       start.date = "2014-01-01", end.date = "2014-01-31",
                       interval = "hour", vector.ws = FALSE)

I am getting this error:

Error in bind_rows_(x, .id) : 
Can not automatically convert from POSIXct, POSIXt to Date in column "date".

Looks like something is terribly wrong with the date column in the data frame. Column date is in the following format:

> str(my_data$date)
Date[1:192840], format: "1993-12-31" "1994-01-01" "1994-01-01" "1994-01-01" 
"1994-01-01" "1994-01-01" "1994-01-01" "1994-01-01" "1994-01-01" ...

Can someone suggest how to fix this error?

UPDATE 1:

Here is sample my_data:

Sr       day      month    year     hour      date          my_value
1        1        1       1994      1         31/12/1993    70.49488
2        1        1       1994      2         01/01/1994    41.3616
3        1        1       1994      3         01/01/1994    30.99245
4        1        1       1994      4         01/01/1994    30.32162
5        1        1       1994      5         01/01/1994    29.91912
6        1        1       1994      6         01/01/1994    26.94829
7        1        1       1994      7         01/01/1994    28.90329
8        1        1       1994      8         01/01/1994    34.25078
9        1        1       1994      9         01/01/1994    30.32162
10       1        1       1994      10        01/01/1994    26.81412
11       1        1       1994      11        01/01/1994    26.69912
12       1        1       1994      12        01/01/1994    28.00245
13       1        1       1994      13        01/01/1994    28.88412
14       1        1       1994      14        01/01/1994    31.01162
15       1        1       1994      15        01/01/1994    26.71829
16       1        1       1994      16        01/01/1994    29.84245
17       1        1       1994      17        01/01/1994    43.33576
18       1        1       1994      18        01/01/1994    39.21494
19       1        1       1994      19        01/01/1994    33.33078
20       1        1       1994      20        01/01/1994    34.11661
21       1        1       1994      21        01/01/1994    36.07161
22       1        1       1994      22        01/01/1994    36.76161
23       1        1       1994      23        01/01/1994    38.4291
24       1        1       1994      24        01/01/1994    34.80661

with:

> str(my_data)
'data.frame':   192840 obs. of  6 variables:
 $ day      : int  1 1 1 1 1 1 1 1 1 1 ...
 $ month    : int  1 1 1 1 1 1 1 1 1 1 ...
 $ year     : int  1994 1994 1994 1994 1994 1994 1994 1994 1994 1994 ...
 $ hour     : int  1 2 3 4 5 6 7 8 9 10 ...
 $ date     : Date, format: "1993-12-31" "1994-01-01" "1994-01-01" "1994-01-01" ...
 $ my_value : num  70.5 41.4 31 30.3 29.9 ...
zx8754
  • 52,746
  • 12
  • 114
  • 209
khajlk
  • 791
  • 1
  • 12
  • 32

1 Answers1

0

The package "openair" use the format POSIXct for date.

Change format with:

library(dplyr)
AQHr <- AQHr %>% 
  mutate(date = paste(year, month, day, hour, sep = "-")) %>% 
  mutate(date = as.POSIXct(strptime(date, format = "%Y-%m-%d-%H", tz = "")))
Novvier
  • 275
  • 1
  • 7