[R-SIG-Finance] 2 time/date columns to one

R. Michael Weylandt michael.weylandt at gmail.com
Fri May 25 18:49:09 CEST 2012


Use xts (always use xts!) and do something like this:

Suppose your data is in three columns called "dat"

xts(dat[,3], as.POSIXct(paste(dat[,1], dat[,2], format = "%m/%d/%Y %H%M"))

This will make an xts of your data taking the third column as the
data-bit and using the first two to make a POSIXct (time) object
converting them using the format specification.

Hope that helps,

Michael

On Fri, May 25, 2012 at 12:35 PM, Costas Vorlow <costas.vorlow at gmail.com> wrote:
> Hello,
>
> I have trouble connecting times with dates to create a "proper" time sequence:
>
> 5/22/2012       1640    318295
> 5/22/2012       1641    432517
> 5/22/2012       1642    328233
> 5/22/2012       1643    444692
> 5/22/2012       1644    217440
> 5/22/2012       1645    650593
> 5/22/2012       1646    207366
> 5/22/2012       1647    334881
> 5/22/2012       1648    133929
> 5/22/2012       1649    267117
> 5/22/2012       1650    179423
> 5/22/2012       1651    259668
> 5/22/2012       1652    341661
>
>
> The table above is a time sequence. The 1st column on the left is the
> date and the next column contains the time of day (1640= 4:40pm). The
> 3rd column is the price of a variable at that point in time. Hence, I
> want to convert the above table to a time series variable (xts, zoo,
> etc) of some sort. Any pointer extremely welcome ( I know this is a
> lame question)...
>
> Many thanks in advance,
>
> Costas
>
> --
>
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> |c|o|s|t|a|s|@|v|o|r|l|o|w|.|o|r|g|
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list