For each element of a list, apply function then combine results into an array.
laply(.data, .fun = NULL, ..., .progress = "none", .inform = FALSE, .drop = TRUE, .parallel = FALSE, .paropts = NULL)
.data | list to be processed |
---|---|
.fun | function to apply to each piece |
... | other arguments passed on to |
.progress | name of the progress bar to use, see
|
.inform | produce informative error messages? This is turned off by default because it substantially slows processing speed, but is very useful for debugging |
.drop | should extra dimensions of length 1 in the output be
dropped, simplifying the output. Defaults to |
.parallel | if |
.paropts | a list of additional options passed into
the |
if results are atomic with same type and dimensionality, a vector, matrix or array; otherwise, a list-array (a list with dimensions)
laply
is similar in spirit to sapply
except
that it will always return an array, and the output is transposed with
respect sapply
- each element of the list corresponds to a row,
not a column.
This function splits lists by elements.
If there are no results, then this function will return a vector of
length 0 (vector()
).
Hadley Wickham (2011). The Split-Apply-Combine Strategy for Data Analysis. Journal of Statistical Software, 40(1), 1-29. http://www.jstatsoft.org/v40/i01/.
laply(baseball, is.factor)#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE#> .id V1 #> 1 id FALSE #> 2 year FALSE #> 3 stint FALSE #> 4 team FALSE #> 5 lg FALSE #> 6 g FALSE #> 7 ab FALSE #> 8 r FALSE #> 9 h FALSE #> 10 X2b FALSE #> 11 X3b FALSE #> 12 hr FALSE #> 13 rbi FALSE #> 14 sb FALSE #> 15 cs FALSE #> 16 bb FALSE #> 17 so FALSE #> 18 ibb FALSE #> 19 hbp FALSE #> 20 sh FALSE #> 21 sf FALSE #> 22 gidp FALSE#> id year stint team lg g ab r h X2b X3b hr rbi #> 1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> sb cs bb so ibb hbp sh sf gidp #> 1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE#> [1] 1 2 3 4 5 6 7 8 9 10#> 1 2 3 4 #> [1,] 1 1 1 1 #> [2,] 2 2 2 2 #> [3,] 3 3 3 3 #> [4,] 4 4 4 4 #> [5,] 5 5 5 5 #> [6,] 6 6 6 6 #> [7,] 7 7 7 7 #> [8,] 8 8 8 8 #> [9,] 9 9 9 9 #> [10,] 10 10 10 10#> , , 1 #> #> 1 2 #> [1,] 1 1 #> [2,] 2 2 #> [3,] 3 3 #> [4,] 4 4 #> [5,] 5 5 #> [6,] 6 6 #> [7,] 7 7 #> [8,] 8 8 #> [9,] 9 9 #> [10,] 10 10 #> #> , , 2 #> #> 1 2 #> [1,] 1 1 #> [2,] 2 2 #> [3,] 3 3 #> [4,] 4 4 #> [5,] 5 5 #> [6,] 6 6 #> [7,] 7 7 #> [8,] 8 8 #> [9,] 9 9 #> [10,] 10 10 #>