funlist: Apply a function to all elements in a list

Description Usage Arguments Value Author(s) See Also Examples

View source: R/funlist.r

Description

Applies a function to the unlisted elements of a list

Usage

1

Arguments

alist

a list

f

a function to be applied

...

further arguments passed on to f

Value

value

Author(s)

Gaston Sanchez

See Also

lapply, sapply

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# say you have some list
list1 = list(1:5, runif(3), rnorm(4))

# get the sum of all elements in list1
funlist(list1, sum)

# get the maximum element in list1
funlist(list1, max)

# say you have missing data
list2 = list(c(1:4, NA), runif(3), rnorm(4))

# get the sum removing NAs
funlist(list2, sum, na.rm=TRUE)

turner documentation built on May 2, 2019, 8:35 a.m.