R/mdply.r
mdply.Rd
Call a multi-argument function with values taken from columns of an data frame or array, and combine results into a data frame
mdply(.data, .fun = NULL, ..., .expand = TRUE, .progress = "none", .inform = FALSE, .parallel = FALSE, .paropts = NULL)
.data | matrix or data frame to use as source of arguments |
---|---|
.fun | function to apply to each piece |
... | other arguments passed on to |
.expand | should output be 1d (expand = FALSE), with an element for each row; or nd (expand = TRUE), with a dimension for each variable. |
.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 |
A data frame, as described in the output section.
The m*ply
functions are the plyr
version of mapply
,
specialised according to the type of output they produce. These functions
are just a convenient wrapper around a*ply
with margins = 1
and .fun
wrapped in splat
.
Call a multi-argument function with values taken from columns of an data frame or array
The most unambiguous behaviour is achieved when .fun
returns a
data frame - in that case pieces will be combined with
rbind.fill
. If .fun
returns an atomic vector of
fixed length, it will be rbind
ed together and converted to a data
frame. Any other values will result in an error.
If there are no results, then this function will return a data
frame with zero rows and columns (data.frame()
).
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/.
#> mean sd V1 V2 #> 1 1 1 1.198777 1.650534 #> 2 2 2 2.687827 4.955065 #> 3 3 3 3.216077 9.379334 #> 4 4 4 -1.904788 5.631554 #> 5 5 5 11.969889 6.801391#> mean sd V1 V2 #> 1 1 1 1.65455025 2.0521554 #> 2 2 1 0.02044487 3.2083856 #> 3 3 1 2.83071992 3.2950298 #> 4 4 1 5.26634059 2.8646567 #> 5 5 1 3.86894620 5.1099934 #> 6 1 2 2.70581082 0.5313243 #> 7 2 2 6.17337713 1.7781613 #> 8 3 2 0.21430589 0.7154185 #> 9 4 2 7.40921747 3.8398527 #> 10 5 2 4.12543752 4.7615698 #> 11 1 3 3.35938859 -0.7368357 #> 12 2 3 1.56371934 3.5793740 #> 13 3 3 8.20073433 7.3459717 #> 14 4 3 8.55457945 2.8479782 #> 15 5 3 10.48137553 3.3455248 #> 16 1 4 -2.46301416 -0.3753259 #> 17 2 4 6.25150583 5.2522328 #> 18 3 4 10.21393344 2.5797252 #> 19 4 4 7.92981345 -2.8532105 #> 20 5 4 1.67192189 9.4019675 #> 21 1 5 0.13089947 1.8940601 #> 22 2 5 -1.49214725 -2.8022458 #> 23 3 5 -1.87711521 1.3071175 #> 24 4 5 9.76173537 6.0255059 #> 25 5 5 2.64538751 4.3337449#> mean sd V1 V2 V3 V4 V5 #> 1 1 1 2.226682 1.332944 0.6529115 0.9014493 1.0347661 #> 2 2 2 2.772254 2.041662 2.0151736 3.8616881 0.6305001 #> 3 3 3 4.012205 1.763587 5.8027834 8.5209502 0.8855410 #> 4 4 4 4.034041 12.136760 -1.3667443 8.6359167 3.1871642 #> 5 5 5 3.109857 13.680555 0.7737609 0.1921425 10.0874553#> mean sd value #> 1 1 1 -0.49605374 #> 2 1 1 -0.18481873 #> 3 1 1 1.63023437 #> 4 1 1 3.10125251 #> 5 1 1 0.38626319 #> 6 2 2 -1.26927654 #> 7 2 2 1.97911777 #> 8 2 2 0.68698772 #> 9 2 2 0.66093312 #> 10 2 2 1.04282194 #> 11 3 3 6.95836895 #> 12 3 3 4.90968828 #> 13 3 3 4.54298335 #> 14 3 3 -2.25412534 #> 15 3 3 5.68079256 #> 16 4 4 4.89215349 #> 17 4 4 6.32326637 #> 18 4 4 3.28871432 #> 19 4 4 6.96386683 #> 20 4 4 0.01022768 #> 21 5 5 -9.69488781 #> 22 5 5 8.59507831 #> 23 5 5 1.50997479 #> 24 5 5 -4.47062922 #> 25 5 5 5.38149624