r - Convert date-time format for use in xts -


i trying convert data xts keep getting "order.by requires appropriate time-based object" error trying convert date time correct format.

my data looks this:

 date      time      value  20090202  9:30      1  20090202  9:31      2  20090202  9:32      3  20090202  9:33      4  20090202  9:34      5  20090202  9:35      6 

i have done well: data.frame(cbind(thedata$date, thedata$time)) yields:

    1         2            20090202    09:30  20090202    09:31  20090202    09:32  20090202    09:33  20090202    09:34  20090202    09:35 

how merge these 1 columnn its:

       1  20090202 09:30  20090202 09:31  20090202 09:32  20090202 09:33  20090202 09:34  20090202 09:35 

so can put xts()

you need use paste on date , time column, call as.posixct on that.

thedata <- read.table(text="date      time      value  20090202  9:30      1  20090202  9:31      2  20090202  9:32      3  20090202  9:33      4  20090202  9:34      5  20090202  9:35      6", header=true, as.is=true) thedata$datetime <- paste(thedata$date, thedata$time) xts(thedata$value, as.posixct(thedata$datetime, format="%y%m%d %h:%m")) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -