Mean recombination – Calculate the elementwise mean of a vector in each value
additional attributes to define the combiner (currently only used internally)
combMean is passed to the argument
This method assumes that the values of the key-value pairs each consist of a numeric vector (with the same length). The mean is calculated elementwise across all the keys.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# Create a distributed data frame using the iris data set bySpecies <- divide(iris, by = "Species") # Add a transformation that returns a vector of sums for each subset, one # mean for each variable bySpeciesTrans <- addTransform(bySpecies, function(x) apply(x, 2, sum)) bySpeciesTrans[] # Calculate the elementwise mean of the vector of sums produced by # the transform, across the keys out1 <- recombine(bySpeciesTrans, combine = combMean) out1 # A more concise (and readable) way to do it bySpecies %>% addTransform(function(x) apply(x, 2, sum)) %>% recombine(combMean) # This manual, non-datadr approach illustrates the above computation # This step mimics the transformation above sums <- aggregate(. ~ Species, data = iris, sum) sums # And this step mimics the mean recombination out2 <- apply(sums[,-1], 2, mean) out2 # These are the same identical(out1, out2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.