R/mean_score.R

Defines functions mean_score

Documented in mean_score

#' mean_score() computes the mean for a given set of variables in a row wise manner
#'
#' @param x,y,z are set of variables from a data frame (i.e. a selection of numeric columns)
#'
#' @return a numeric vector
#'
#' @details simple wrapper to produce row wise means (default is na.rm=TRUE)
#'
#' @examples
#' library(dplyr)
#' data_frame %>%
#' mutate(score =  mean_score(x, z, y))
#'
#'
#' @export
mean_score <- function(..., na.rm=TRUE){
rowMeans(cbind(...), na.rm=na.rm)
# source: https://stackoverflow.com/questions/33401788/dplyr-using-mutate-like-rowmeans
# by: https://stackoverflow.com/users/1191259/frank
}
dacarras/r4sda documentation built on Nov. 9, 2023, 10:17 a.m.