safe_mean: Calculate 'mean' but return NA rather than NaN when values...

View source: R/summarise.R

safe_meanR Documentation

Calculate mean but return NA rather than NaN when values are missing

Description

This function is a drop-in replacement for mean, which is used in cat_summarise. It returns NA rather than NaN when all values are NA.

Usage

safe_mean(x, na.rm = FALSE)

Arguments

x

A numerical vector.

na.rm

A boolean indicating whether to remove NAs.

Value

The mean of x or NA when values are missing.


olihawkins/tabbycat documentation built on Aug. 27, 2023, 10:15 a.m.