ilap: Iterate over sequence length of input and return list(s)

ilap(.data, .f, ...)

Arguments

.data

Object representing the sequence length, used as ".i" in the .f expression. If matrix or data frame, sequence length will be determined by the number of columns. If integer, then it will be passed directly onto function call, otherwise the object will be converted into a sequence from 1 to the length of the object.

.f

Function to apply to each element (as an integer position) of input object. This can be written as a single function name e.g., mean, a formula-like function call where '.i' is assumed to be the integer position of input data object e.g., ~ mean(mtcars[[.i]]), or an in-line function definition e.g., function(x) mean(mtcars[[x]]).

...

Other values passed to function call.

Value

A list

See also

Other lap: lap

Examples

## return string list ilap(1:10, ~ paste0(letters[.i], rev(LETTERS)[.i]))
#> [[1]] #> [1] "aZ" #> #> [[2]] #> [1] "bY" #> #> [[3]] #> [1] "cX" #> #> [[4]] #> [1] "dW" #> #> [[5]] #> [1] "eV" #> #> [[6]] #> [1] "fU" #> #> [[7]] #> [1] "gT" #> #> [[8]] #> [1] "hS" #> #> [[9]] #> [1] "iR" #> #> [[10]] #> [1] "jQ" #>
## return list of columns ilap(mtcars, ~ c(row.names(mtcars)[.i], mtcars$wt[.i]))
#> [[1]] #> [1] "Mazda RX4" "2.62" #> #> [[2]] #> [1] "Mazda RX4 Wag" "2.875" #> #> [[3]] #> [1] "Datsun 710" "2.32" #> #> [[4]] #> [1] "Hornet 4 Drive" "3.215" #> #> [[5]] #> [1] "Hornet Sportabout" "3.44" #> #> [[6]] #> [1] "Valiant" "3.46" #> #> [[7]] #> [1] "Duster 360" "3.57" #> #> [[8]] #> [1] "Merc 240D" "3.19" #> #> [[9]] #> [1] "Merc 230" "3.15" #> #> [[10]] #> [1] "Merc 280" "3.44" #> #> [[11]] #> [1] "Merc 280C" "3.44" #>