Search code examples
rstatisticstime-seriesfinance

R tick data : merging date and time into a single object


I'm currently working in tick data with R and I would like to merge date and time into a single object as I need to get a precise time object to compute some statistics on my data. Here is how my data looks like:

               date       time      price flag    exchange
2   XXH10   2010-02-02   08:00:03   2787 1824        E
3   XXH10   2010-02-02   08:00:04   2786    3        E
4   XXH10   2010-02-02   08:00:04   2787    6        E
5   XXH10   2010-02-02   08:00:04   2787    1        E
6   XXH10   2010-02-02   08:00:04   2787    1        E

Basically, I would like to merge the columns "date" and "time" into a single one.


Solution

  • Create a datetime object with as.POSIXct:

    as.POSIXct(paste(x$date, x$time), format="%Y-%m-%d %H:%M:%S")
    [1] "2010-02-02 08:00:03 GMT" "2010-02-02 08:00:04 GMT" "2010-02-02 08:00:04 GMT"
    [4] "2010-02-02 08:00:04 GMT" "2010-02-02 08:00:04 GMT"