by2df | R Documentation |
Convert the output from the by function to a data frame
by2df(x, format = c("wide", "long", "array"), name = "output")
x |
produced by stats::by |
format |
type of output, or a formula passed to dcast |
name |
assigned to the output variable |
The stats::by function produces list-like objects, which can be converted to arrays or data frames
data('meuse', package='sp')
byRes = by(meuse[,c('copper','lead')], meuse[, c('landuse','soil')], range)
dimnames(by2df(byRes, 'array'))
head(by2df(byRes, 'wide'))
head(by2df(byRes, 'long'))
if(requireNamespace('reshape2', quietly=TRUE)) {
head(reshape2::dcast(by2df(byRes, 'long'), landuse ~ soil + output))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.