datadr (version 0.8.4)

combDdf: "DDF" Recombination

Description

"DDF" recombination - results into a "ddf" object, rbinding if necessary

Usage

combDdf(...)

Arguments

...
additional attributes to define the combiner (currently only used internally)

Details

combDdf is passed to the argument combine in recombine.

If the value of the "ddo" object that will be recombined is a list, then the elements in the list will be collapsed together via rbind.

See Also

divide, recombine, combCollect, combMeanCoef, combRbind, combDdo, combDdf

Examples

Run this code
# Divide the iris data
bySpecies <- divide(iris, by = "Species")

## Simple combination to form a ddf
##---------------------------------------------------------

# Add a transform that selects the petal width and length variables
selVars <- function(x) x[,c("Petal.Width", "Petal.Length")]

# Apply the transform and combine using combDdo
combined <- recombine(addTransform(bySpecies, selVars), combine = combDdf)
combined
combined[[1]]

# A more concise (and readable) way to do it
bySpecies %>%
  addTransform(selVars) %>%
  recombine(combDdf)

## Combination that involves rbinding to give the ddf
##---------------------------------------------------------

# A transformation that returns a list
listTrans <- function(x) {
  list(meanPetalWidth = mean(x$Petal.Width),
       maxPetalLength = max(x$Petal.Length))
}

# Apply the transformation and look at the result
bySpeciesTran <- addTransform(bySpecies, listTrans)
bySpeciesTran[[1]]

# And if we rbind the "value" of the first subset:
out1 <- rbind(bySpeciesTran[[1]]$value)
out1

# Note how the combDdf method row binds the two data frames
combined <- recombine(bySpeciesTran, combine = combDdf)
out2 <- combined[[1]]
out2

# These are equivalent
identical(out1, out2$value)

Run the code above in your browser using DataCamp Workspace