R/arrayToLong.R

Defines functions arrayToLong

Documented in arrayToLong

#' Reshape array of data matrices into long format
#'
#' @import foreach
#' 
#' @param X 3 dimensional array of matrices to extract to long format
#' @param coords Spatial coordinates associated with the data (longitude in first column)
#' @param yrs Vector with labels for the years
#' 
#' 

arrayToLong = function(X, coords, yrs) {
  
  X.dim = dim(X)
  
  foreach(t = 1:X.dim[length(X.dim)], .combine = 'rbind') %do% {
    if(length(X.dim)==3)
      data.frame(lon = coords[,1], lat = coords[,2], time = yrs[t], X = X[,,t])
    else if(length(X.dim)==2)
      data.frame(lon = coords[,1], lat = coords[,2], time = yrs[t], X = X[,t])
  }
  
}

Try the telefit package in your browser

Any scripts or data that you put into this service are public.

telefit documentation built on Feb. 4, 2020, 9:08 a.m.