Learn R Programming

dateutils (version 0.1.5)

mean_na: Return the mean

Description

Return the mean of `x`. If no observations, return `NA`. This is a workaround for the fact that in data.table, `:= mean(x, na.rm = TRUE)` will return `NaN` where there are no observations

Usage

mean_na(x)

Arguments

x

data potentially with non-finite values

Value

Mean of the input

Examples

Run this code
# NOT RUN {
mean_na(c(1,2,3,7,9,NA)) ## 4.4
# }

Run the code above in your browser using DataLab