Learn R Programming

petersenlab (version 1.0.0)

mySum: My Sum.

Description

Compute a row sum and retain NAs when all values in the row are NA.

Usage

mySum(data)

Value

Modified row sum to set row sum to be missing when all values in the row are missing (NA).

Arguments

data

dataframe

Details

Compute a row sum and set the row sum to be missing (not zero) when all values in the row are missing (NA).

See Also

Other computations: Mode(), meanSum()

Examples

Run this code
# Prepare Data
df <- data.frame(item1 = rnorm(1000), item2 = rnorm(1000), item3 = rnorm(1000))
df[sample(1:nrow(df), size = 100), c("item1","item2","item3")] <- NA

# Calculate Missingness-Adjusted Row Sum
df$sum <- mySum(df)

Run the code above in your browser using DataLab