aggregateScale: aggregateScale()

View source: R/aggregateScale.R

aggregateScaleR Documentation

aggregateScale()

Description

Calculates the mean or sum of each row of a dataframe using rowMeans() while applying a condition to only aggregate rows where missingess is below a certain threshold.

Usage

aggregateScale(dataframe, aggregate = "SUM", NA.threshold = 0.5, na.rm = TRUE)

Arguments

dataframe

A dataframe containing numeric scores to be aggregated. Each row should correspond to one observation. Each column is one variable.

aggregate

Defaults to "SUM". Calculates sum scores, use "MEAN" for mean scores.

NA.threshold

The maximum proportion of missingness allowed for one observation/row before the aggregate score is coerced to NA. Defaults to 0.5, which means that rows with NA in more than half of its observation will have an NA aggregate score.

na.rm

Whether missing values should be ignored in the calculation for the aggregate scores. Defaults to TRUE. Does not affect the calculation of proportion of missing data in NA.threshold.

Examples

mydata <- data.frame(a = c(1:8,NA,NA), b = 1:10, c = rep(NA,10))
aggregateScale(mydata)
aggregateScale(mydata, NA.threshold = 0.2) # less than 0.2 missingness

Aaron0696/aaRon documentation built on July 27, 2023, 2:05 p.m.