PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/demo/gsubfn-chron.R

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