R/print.mc.R

Defines functions print.mcnode print.mc

Documented in print.mc print.mcnode

#' Print a mcnode or mc Object
#'
#' Prints a description of the structure of a \samp{mc} or \samp{mcnode} object.
#'
#' @param x a \samp{mcnode} or a \samp{mc} object.
#' @param digits number of digits to be used.
#' @param ... further arguments to be passed to the print function.
#' @return an invisible data frame.
#' @seealso \code{\link{mcnode}} for \samp{mcnode} objects, \code{\link{mc}} for \samp{mc} objects.
#' @keywords print
#' @name print.mc
#' @examples
#' data(total)
#' print(xVU)
#' print(total)
#' @export
print.mc <- function(x, digits=3,...)
{
  outm <- lapply(x,attr,which="outm")
  type <- lapply(x,attr,which="type")
  dimm <- lapply(x,dim)
  nom <- names(x)

  sortie <- function(obj,x=1,out,typ){
    dimm <- dim(obj)
    rangem <- range(obj,na.rm=TRUE)
    return(data.frame(
      node=nom[i],
      mode=mode(obj),
      nsv=dimm[1],
      nsu=dimm[2],
      nva=nvariates,
      variate=x,
      min=rangem[1],
      mean=mean(obj,na.rm=TRUE),
      median=median(as.vector(obj) * 1,na.rm=TRUE),   # For logical (and always a double, as in previous versions)
      max=rangem[2],
      Nas=sum(is.na(unclass(obj))),
      type=type[[i]],
      outm=out
    ))
  }

  res <- data.frame(NULL)
  for(i in seq_along(x)){
    nvariates <- dimm[[i]][3]
      if(outm[[i]][1]=="none") next
      if(outm[[i]][1]=="each"){
        for(j in 1:nvariates)
          res <- rbind(res,sortie(x[[i]][,,j,drop=FALSE],j,outm[[i]]))
      } else {
      for(func in outm[[i]]){
          tmp <- .outm_reduce(x[[i]], func)                                # vectorized for usual functions
          res <- rbind(res,sortie(tmp,NA,func))
          }
  }
  }

 if(is.null(unlist(res))) {
  warning("Try to print a multivariate node with outm = none", call.=FALSE)
  res <- NULL}

 invisible(print(res,digits=digits,...))
}

#' @rdname print.mc
#' @export
print.mcnode <- function(x,...)
{
  print.mc(list(x=x),...)}

Try the mc2d package in your browser

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

mc2d documentation built on Oct. 23, 2026, 1:06 a.m.