[R-SIG-Finance] 2 time/date columns to one
chuck
cfriedem at gmail.com
Fri May 25 18:58:34 CEST 2012
In order to create a zoo or xts object, you need to provide a time-like index
to the xts/zoo object constructor. Something like the following may work for
you:
# make dummy data
dates <- rep("5/22/2012",10)
times <- 1640 + 0:9
prices <- rnorm(10,20000,10000)
# now use data to build xts object
series <- xts(prices, as.POSIXct(paste(dates,times), format="%m/%d/%Y
%H%M"))
If these columns are coming from a csv file, you can use read.zoo's index
function argument to do it all in one step:
# say your dates are column 1, and times are column 2, prices are column 3
of your csv file...
index.func <- function(dd,tt) as.POSIXct(paste(dd,tt), format="%m/%d/%Y
%H%M")
series <- read.zoo(file = "file.csv", colClasses =
c("character","character","numeric"), index.column=list(1,2),
FUN=index.func)
I hope that makes sense.
--
View this message in context: http://r.789695.n4.nabble.com/2-time-date-columns-to-one-tp4631353p4631359.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list