diff --git a/NAMESPACE b/NAMESPACE index e56046b..5939db6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,7 +31,9 @@ export(twdtwApplyParallel) export(twdtwClassify) exportMethods("[") exportMethods("[[") +exportMethods(as.data.frame) exportMethods(as.list) +exportMethods(as.twdtwTimeSeries) exportMethods(bands) exportMethods(coordinates) exportMethods(coverages) @@ -84,6 +86,7 @@ import(zoo) importFrom(RColorBrewer,brewer.pal) importFrom(Rdpack,reprompt) importFrom(caret,createDataPartition) +importFrom(data.table,rbindlist) importFrom(dtw,asymmetric) importFrom(dtw,rabinerJuangStepPattern) importFrom(dtw,symmetric1) diff --git a/R/methods.R b/R/methods.R index 26d8290..5babda6 100644 --- a/R/methods.R +++ b/R/methods.R @@ -18,6 +18,9 @@ setGeneric("layers", setGeneric("coverages", function(x) standardGeneric("coverages")) +setGeneric("as.twdtwTimeSeries", + function(x) standardGeneric("as.twdtwTimeSeries")) + setGeneric("bands", function(x) standardGeneric("bands")) @@ -33,6 +36,14 @@ setGeneric("is.twdtwRaster", setGeneric("projecttwdtwRaster", function(x, ...) standardGeneric("projecttwdtwRaster")) +as.data.frame.twdtwTimeSeries <- function(x){ + lapply(x[], function(y){ + out <- data.frame(date = index(y), y) + rownames(out) <- NULL + return(out) + }) +} + as.list.twdtwTimeSeries = function(x) lapply(seq_along(x), function(i) new("twdtwTimeSeries", x[[i]], labels(x)[i]) ) @@ -296,6 +307,11 @@ setMethod("as.list", "twdtwMatches", as.list.twdtwMatches) #' @export setMethod("as.list", "twdtwRaster", as.list.twdtwRaster) +#' @inheritParams twdtwTimeSeries-class +#' @rdname twdtwTimeSeries-class +#' @export +setMethod("as.data.frame", "twdtwTimeSeries", as.data.frame.twdtwTimeSeries) + #' @inheritParams twdtwTimeSeries-class #' @param i indices of the time series. #' @rdname twdtwTimeSeries-class @@ -575,6 +591,13 @@ setMethod(f = "show", "twdtwMatches", setMethod(f = "show", "twdtwRaster", definition = show.twdtwRaster) +#' @aliases as.twdtwTimeSeries +#' @inheritParams twdtwTimeSeries-class +#' @describeIn twdtwTimeSeries convert list of data.frame to class twdtwTimeSeries. +#' @export +setMethod("as.twdtwTimeSeries", "ANY", + function(x) twdtwTimeSeries(lapply(x[], function(y) zoo(y[, names(y)!="date"], order.by = y$date)))) + #' @aliases is.twdtwTimeSeries #' @inheritParams twdtwTimeSeries-class #' @describeIn twdtwTimeSeries Check if the object belongs to the class twdtwTimeSeries. diff --git a/inst/lucc_MT/patterns/patt.rds b/inst/lucc_MT/patterns/patt.rds new file mode 100644 index 0000000..8ac5dd4 Binary files /dev/null and b/inst/lucc_MT/patterns/patt.rds differ diff --git a/man/twdtwTimeSeries-class.Rd b/man/twdtwTimeSeries-class.Rd index 5ab4ade..d9c4af8 100644 --- a/man/twdtwTimeSeries-class.Rd +++ b/man/twdtwTimeSeries-class.Rd @@ -12,11 +12,14 @@ \alias{ncol,twdtwTimeSeries-method} \alias{length,twdtwTimeSeries-method} \alias{as.list,twdtwTimeSeries-method} +\alias{as.data.frame,twdtwTimeSeries-method} \alias{[,twdtwTimeSeries,ANY,ANY,ANY-method} \alias{[[,twdtwTimeSeries,ANY,ANY-method} \alias{labels,twdtwTimeSeries-method} \alias{levels,twdtwTimeSeries-method} \alias{show,twdtwTimeSeries-method} +\alias{as.twdtwTimeSeries,ANY-method} +\alias{as.twdtwTimeSeries} \alias{is.twdtwTimeSeries,ANY-method} \alias{is.twdtwTimeSeries} \title{class "twdtwTimeSeries"} @@ -35,6 +38,8 @@ \S4method{as.list}{twdtwTimeSeries}(x) +\S4method{as.data.frame}{twdtwTimeSeries}(x) + \S4method{[}{twdtwTimeSeries,ANY,ANY,ANY}(x, i) \S4method{[[}{twdtwTimeSeries,ANY,ANY}(x, i) @@ -45,6 +50,8 @@ \S4method{show}{twdtwTimeSeries}(object) +\S4method{as.twdtwTimeSeries}{ANY}(x) + \S4method{is.twdtwTimeSeries}{ANY}(x) } \arguments{ @@ -66,6 +73,8 @@ Class for setting irregular time series. \itemize{ \item \code{twdtwTimeSeries}: Create object of class twdtwTimeSeries. +\item \code{as.twdtwTimeSeries}: convert list of data.frame to class twdtwTimeSeries. + \item \code{is.twdtwTimeSeries}: Check if the object belongs to the class twdtwTimeSeries. }}