[R] how to transform db query result into a set of timeseries ?
stef.mientki at gmail.com
Mon Sep 5 22:28:50 CEST 2016
I've a number of timeseries into a database and want to display these
timeseries into graph.
Now the code below works well, but as the user can select which
timeseries should be shown (up to 20 timeseries) the code below should
be dynamic and can be quiet large and complex.
Is there an easier way to convert a database result into timeseries
accepted by dygraph ?
SQL <- "select Date, M, G, N from Compare_Model"
df <- dbGetQuery ( con, statement = SQL )
zon1 <- xts ( df$M, as.POSIXct ( df$Date, format="%Y-%m-%d
zon2 <- xts ( df$G, as.POSIXct ( df$Date, format="%Y-%m-%d
zon3 <- xts ( df$N, as.POSIXct ( df$Date, format="%Y-%m-%d
zonnen <- Reduce ( function(...) merge(..., all=TRUE ), list ( zon,
zon2, zon3 ))
dygraph ( zonnen )
More information about the R-help