0

I have a dataset that the timestamp was not stored in one single column. The timestamp was separated in different six columns as YY, MM, DD, hh, mm and ss.

Here is it looks like:

  YY    MM    DD    hh    mm    ss
  15     6    12    16     0    10
  15     6    12    16     1    10
  15     6    12    16     2    10
  15     6    12    16     3    10
  15     6    12    16     4    10
  15     6    12    16     5    10
  15     6    12    16     6    10
  15     6    12    16     7    10
  15     6    12    16     8    10
  15     6    12    16     9    10
  15     6    12    16    10    10
  15     6    12    16    12    10
  15     6    12    16    13    10
  15     6    12    16    14    10
  15     6    12    16    15    10
  15     6    12    16    16    10
  15     6    12    16    17    10
  15     6    12    16    18    10
  15     6    12    16    19    10
  15     6    12    16    20    10

Please let me know know how to convert to POSIXct format that can be further used in ggplot2.

nrussell
  • 18,382
  • 4
  • 47
  • 60
Kuo-Hsien Chang
  • 925
  • 17
  • 40

1 Answers1

1

paste variables into one and then convert to POSIX.

as.POSIXct(paste(15,     6,    12,    16,     0,    10), format = "%y %m %d %H %M %S")

change paste to your columns:

as.POSIXct(paste(df$YY, df$MM, df$DD, df$hh, df$mm, df$ss), format = "%y %m %d %H %M %S")
Jav
  • 2,203
  • 13
  • 22