R/utils.R

Defines functions array2list list2array

list2array <- function(xlist){
  d1 <- unique(vapply(xlist, NROW, numeric(1)))
  if(length(d1) != 1) stop("Different row number")
  d2 <- unique(vapply(xlist, NCOL, numeric(1)))
  if(length(d2) != 1) stop("Different col number")
  array(unlist(xlist), dim = (c(d1, d2, length(xlist))))
}

array2list <- function(xarray){
  out <- vector("list", length= dim(xarray)[[3]])
  for(i in seq_len(dim(xarray)[[3]])) {
    out[[i]] <- xarray[,,i]
  }
  out
}

Try the flap package in your browser

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

flap documentation built on June 22, 2024, 9:16 a.m.