R/sum.n.R

Defines functions sum.n

Documented in sum.n

### -*-      Coding: utf-8   -*-       ###
### Analyste: Charles-Édouard Giguère. ###

### Sum that is weighted by the number of non missing values.
### if less value than n are missing it returns NA.

sum.n <- function (x, n = 1, ...){
    n.val <- sum(!is.na(x))
    l.val <- length(x)
    if (n.val >= n){
        return(mean(x, na.rm = TRUE, ...) * l.val)
    }
    else{
        return(NA)
    }
}

Try the CUFF package in your browser

Any scripts or data that you put into this service are public.

CUFF documentation built on May 30, 2017, 7:39 a.m.