napply: NApply

Description Usage Arguments Details Value

Description

Apply a function raggedly to a vector containing NAs.

Usage

1
napply(x, FUN)

Arguments

x

a vector

FUN

a function

Details

Each consecutive stretch of non-NA values is treated as a separate input to the function (using ave). Can be used as a generalised method for functions that don't have a na.omit option or when it's important to maintain data structure and order.

The function is best used for FUNs which return an output of the same size as the input. If FUN returns an atomic value for an input vector (eg mean) the output is replicated across all entries of x as necessary.

Value

A vector of the same size and NA distribution as x but containing FUN-transformed data.


PaolaCognigni/CTraxHelper documentation built on May 7, 2019, 11:57 p.m.