/demo/gsubfn-chron.R
http://gsubfn.googlecode.com/ · R · 22 lines · 12 code · 6 blank · 4 comment · 0 complexity · b02f0d688c7af2f2f012ebca2c3b2f66 MD5 · raw file
- # Use read.zoo to read data with a chron time index
- # Ignore fractional seconds.
-
- library(zoo)
- library(chron)
- library(gsubfn)
-
- # test data
- Lines <- "2006-01-24 02:41:24.00011,1.22930000,5,1.22950000,7
- 2006-01-25 04:41:24.00011,1.22930000,5,1.22950000,7
- 2006-01-26 07:41:24.00011,1.22930000,5,1.22950000,7"
-
- # convert to chron
- to.chron <- function(x)
- strapply(format(x), "([0-9-]+) ([0-9:]+)",
- ~ chron(as.numeric(as.Date(dd)), tt), simplify = c)
-
- con <- textConnection(Lines)
- read.zoo(con, sep = ",", FUN = to.chron)
- close(con)