enumerate: Enumerate over a Vector

Description Usage Arguments Examples

View source: R/enumerate.R

Description

This function extends lapply to operate on functions taking two arguments – the first refers to each element within a vector, while the second refers to the current index.

Usage

1
enumerate(X, FUN, ...)

Arguments

X

A vector.

FUN

A function, taking two arguments.

...

Optional arguments to FUN.

Examples

1
2
3
4
5
6
data <- setNames( list(1, 2, 3), c('a', 'b', 'c') )
v <- replicate(10, rnorm(1E3), simplify=FALSE)
identical( lapply(v, sum), enumerate(v, sum) )
f <- function(x, i) i
enumerate(v, f)
enumerate(v, function(x, i) i)

kevinushey/Kmisc documentation built on May 20, 2019, 9:08 a.m.