For each element of a list, apply function, keeping results as a list.
llply(.data, .fun = NULL, ..., .progress = "none", .inform = FALSE, .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 |
.parallel | if |
.paropts | a list of additional options passed into
the |
list of results
llply
is equivalent to lapply
except that it will
preserve labels and can display a progress bar.
This function splits lists by elements.
If there are no results, then this function will return
a list of length 0 (list()
).
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/.
llply(llply(mtcars, round), table)#> $mpg #> #> 10 13 14 15 16 17 18 19 20 21 22 23 24 26 27 30 32 34 #> 2 1 1 4 3 1 2 3 1 4 1 2 1 1 1 2 1 1 #> #> $cyl #> #> 4 6 8 #> 11 7 14 #> #> $disp #> #> 71 76 79 95 108 120 121 141 145 147 160 168 225 258 276 301 304 318 350 351 #> 1 1 2 1 1 2 1 1 1 1 2 2 1 1 3 1 1 1 1 1 #> 360 400 440 460 472 #> 2 1 1 1 1 #> #> $hp #> #> 52 62 65 66 91 93 95 97 105 109 110 113 123 150 175 180 205 215 230 245 #> 1 1 1 2 1 1 1 1 1 1 3 1 2 2 3 3 1 1 1 2 #> 264 335 #> 1 1 #> #> $drat #> #> 3 4 5 #> 13 18 1 #> #> $wt #> #> 2 3 4 5 #> 8 13 8 3 #> #> $qsec #> #> 14 15 16 17 18 19 20 23 #> 1 2 3 9 5 7 4 1 #> #> $vs #> #> 0 1 #> 18 14 #> #> $am #> #> 0 1 #> 19 13 #> #> $gear #> #> 3 4 5 #> 15 12 5 #> #> $carb #> #> 1 2 3 4 6 8 #> 7 10 3 10 1 1 #>llply(baseball, summary)#> $id #> Length Class Mode #> 21699 character character #> #> $year #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 1871 1937 1970 1961 1988 2007 #> #> $stint #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 1.000 1.000 1.000 1.093 1.000 4.000 #> #> $team #> Length Class Mode #> 21699 character character #> #> $lg #> Length Class Mode #> 21699 character character #> #> $g #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 29.00 59.00 72.82 125.00 165.00 #> #> $ab #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.0 25.0 131.0 225.4 435.0 705.0 #> #> $r #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 2.00 15.00 31.78 58.00 177.00 #> #> $h #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 4.00 32.00 61.76 119.00 257.00 #> #> $X2b #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 0.00 5.00 10.45 19.00 64.00 #> #> $X3b #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.000 0.000 1.000 2.194 3.000 28.000 #> #> $hr #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.000 0.000 1.000 5.234 7.000 73.000 #> #> $rbi #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.00 1.00 14.00 29.59 51.00 184.00 12 #> #> $sb #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.000 0.000 1.000 5.168 5.000 130.000 250 #> #> $cs #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.0 0.0 0.0 2.1 3.0 42.0 4525 #> #> $bb #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 0.00 1.00 11.00 22.49 38.00 232.00 #> #> $so #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.00 4.00 19.00 29.26 45.00 189.00 1305 #> #> $ibb #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.000 0.000 0.000 2.292 3.000 120.000 7528 #> #> $hbp #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.000 0.000 0.000 1.543 2.000 51.000 377 #> #> $sh #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.000 0.000 1.000 3.388 5.000 52.000 960 #> #> $sf #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.000 0.000 1.000 1.842 3.000 19.000 7390 #> #> $gidp #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's #> 0.000 0.000 2.000 4.774 8.000 36.000 5272 #># Examples from ?lapply x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE)) llply(x, mean)#> $a #> [1] 5.5 #> #> $beta #> [1] 4.535125 #> #> $logic #> [1] 0.5 #>llply(x, quantile, probs = 1:3/4)#> $a #> 25% 50% 75% #> 3.25 5.50 7.75 #> #> $beta #> 25% 50% 75% #> 0.2516074 1.0000000 5.0536690 #> #> $logic #> 25% 50% 75% #> 0.0 0.5 1.0 #>