R/meanNeighbors.R

Defines functions meanNeighbors

Documented in meanNeighbors

#' Helper function to obtain running means for prodlim objects.
#' 
#' Compute average values of a variable according to neighborhoods.
#' 
#' 
#' @param x Object of class \code{"neighborhood"}.
#' @param y Vector of numeric values.
#' @param \dots Not used.
#' @author Thomas Alexander Gerds <tag@@biostat.ku.dk>
#' @seealso \code{\link{neighborhood}}
#' @keywords survival
#' @examples
#' 
#' meanNeighbors(x=1:10,y=c(1,10,100,1000,1001,1001,1001,1002,1002,1002))
#'
#' @export
meanNeighbors <- function(x,y,...){
  nnn=neighbors(x,y,...)
  out <- data.frame(x=nnn$nbh$values,
                    y=sapply(nnn$list,mean))
  names(out) <- c("uniqueX","averageY")
  out
}

Try the prodlim package in your browser

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

prodlim documentation built on June 24, 2024, 5:08 p.m.