From 7c6c2e09e3ad1d41f26869cb7b9f9882175c8a6e Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Tue, 10 Mar 2020 12:27:53 +0000 Subject: Initial commit --- examples/R/load_dataset.R | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/R/load_dataset.R (limited to 'examples/R/load_dataset.R') diff --git a/examples/R/load_dataset.R b/examples/R/load_dataset.R new file mode 100644 index 0000000..8ef0e22 --- /dev/null +++ b/examples/R/load_dataset.R @@ -0,0 +1,41 @@ +#' --- +#' title: Example code to load a TCPD time series +#' author: G.J.J. van den Burg +#' date: 2020-01-06 +#' license: See the LICENSE file. +#' copyright: 2019, The Alan Turing Institute +#' --- + +library(RJSONIO) + +load.dataset <- function(filename) +{ + data <- fromJSON(filename) + + # reformat the data into a data frame with a time index and the data values + tidx <- data$time$index + + cols <- c() + + mat <- NULL + for (j in 1:data$n_dim) { + s <- data$series[[j]] + v <- NULL + for (i in 1:data$n_obs) { + val <- s$raw[[i]] + if (is.null(val)) { + v <- c(v, NA) + } else { + v <- c(v, val) + } + } + cols <- c(cols, s$label) + mat <- cbind(mat, v) + } + + mat <- cbind(tidx, mat) + colnames(mat) <- c('t', cols) + + df <- as.data.frame(mat) + return(df) +} -- cgit v1.2.3