this_by_n: Apply This By Every n Values

Description Usage Arguments Value Author(s) References Examples

View source: R/this_by_n.R

Description

Applies a function by every n values to a vector.

Usage

1
this_by_n(invec, n = 3, FUN = sum, fill = NA, include_first = TRUE)

Arguments

invec

The input vector.

n

By how many values?

FUN

The function to apply to each set of n values.

fill

The value to padd the resulting vector with. Defaults to NA.

include_first

Logical. Should the first value be included. Defaults to TRUE.

Value

A vector the same length as the input vector.

Author(s)

Ananda Mahto

References

http://stackoverflow.com/q/34563693/1270695

Examples

1
2
3
4
5
x <- c(1, 2, 3, 4, 7, 9, 2, 4)
this_by_n(x, 3, mean)
this_by_n(x, 2, max)
this_by_n(x, 4, min)
this_by_n(letters[1:10], 5, toString)

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.