R/mean.folder.R

Defines functions mean.folder

Documented in mean.folder

mean.folder <- function(x, ..., na.rm = FALSE) {
  # 'mean' method for objects of class 'folder': colMeans per data frame.
  
  fold <- x
  
  # Check the arguments
  if (!attr(fold, "same.cols"))
    stop("'mean' cannot be applied to a folder with different column names.")
  
  x <- fold[[1]]
  jnum <- logical(ncol(x))
  for (j in 1:ncol(x)) {
    jnum[j] <- is.numeric(x[, j])
  }
  
  notnum <- colnames(x)[!jnum]
  if (length(notnum) > 0)
    warning(paste("There are omitted variables (non numeric):   ", paste(notnum, collapse = "   "), sep = ""), immediate. = TRUE)
  
  fold.num <- vector("list", length(fold))
  for (n in 1:length(fold.num))
    fold.num[[n]] <- fold[[n]][jnum]
  names(fold.num) <- names(fold)
  
  return(lapply(fold.num, colMeans, na.rm = na.rm))
}

Try the dad package in your browser

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

dad documentation built on Sept. 2, 2017, 1:04 a.m.