R/unmatrix.R

Defines functions unmatrix

Documented in unmatrix

unmatrix <- function(x, byrow=FALSE)
{
  rnames <- rownames(x)
  cnames <- colnames(x)
  if(is.null(rnames)) rnames <- paste("r",1:nrow(x),sep='')
  if(is.null(cnames)) cnames <- paste("c",1:ncol(x),sep='')
  nmat <- outer(rnames, cnames, paste, sep=":")

  if(byrow)
  {
    vlist <- c(t(x))
    names(vlist) <- c(t(nmat))
  }
  else
  {
    vlist <- c(x)
    names(vlist) <- c(nmat)
  }

  return(vlist)
}

Try the gdata package in your browser

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

gdata documentation built on Oct. 17, 2023, 1:11 a.m.