-1

I have DateTime columns (time series) in the form of dd/mm/yyyy hh:mm with a gap of 15 minutes. This is the structure of my data frame:

str(WAC)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   15840 obs. of  5 variables:

 $ Site           : chr  "WAC" "WAC" "WAC" "WAC" ...

 $ ReadingDateTime: chr  "01/07/2019 00:00" "01/07/2019 00:15" "01/07/2019 00:30" "01/07/2019 00:45" ...

 $ NO_WAC         : num  9 5 10 5 4 7 2 1 4 2 ...

 $ NO2_WAC        : num  18 18 21 14 11 15 7 9 11 10 ...

 $ PM10_WAC       : num  8.6 8.2 8.4 6.7 5 7.8 7.5 7.8 5.5 7 ...

However, the 97th entry of ReadingDateTime colum is 01/08/2019 00:00, which means that there is a change of mm instead of dd in dd/mm/yyyy. Obviously, I want the time variable to change by dd, how can I do that?

broti
  • 1,338
  • 8
  • 29
  • Please learn how to make a minimal, self-contained, reproducible example, read: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – jay.sf Mar 25 '20 at 12:28
  • 1
    @Prashant Garg - That the entry following `"01/07/2019 23:45"` is `"01/08/2019 00:00"` proves that your assumption "_I have DateTime columns (time series) in the form of dd/mm/yyyy hh:mm_" is **wrong**; in fact, you have the form mm/dd/yyyy. Now to rectify this, you'd have to show how the `DateTime`s were generated. – Armali Mar 25 '20 at 12:34

1 Answers1

0

I guess you want the seq.POSIXt function:

d1 <- as.POSIXct("2019-07-01 00:00") 
d2 <- as.POSIXct("2019-08-01 00:00")
ReadingDateTime <- seq.POSIXt(d1, d2, by=15*60)

> ReadingDateTime
   [1] "2019-07-01 00:00:00 +07" "2019-07-01 00:15:00 +07" "2019-07-01 00:30:00 +07"
   [4] "2019-07-01 00:45:00 +07" "2019-07-01 01:00:00 +07" "2019-07-01 01:15:00 +07"
   [7] "2019-07-01 01:30:00 +07" "2019-07-01 01:45:00 +07" "2019-07-01 02:00:00 +07"
...
  [94] "2019-07-01 23:15:00 +07" "2019-07-01 23:30:00 +07" "2019-07-01 23:45:00 +07"
  [97] "2019-07-02 00:00:00 +07" "2019-07-02 00:15:00 +07" "2019-07-02 00:30:00 +07"
Edward
  • 10,360
  • 2
  • 11
  • 26