by2df: Convert by to data.frame

View source: R/by.R

by2dfR Documentation

Convert by to data.frame

Description

Convert the output from the by function to a data frame

Usage

by2df(x, format = c("wide", "long", "array"), name = "output")

Arguments

x

produced by stats::by

format

type of output, or a formula passed to dcast

name

assigned to the output variable

Details

The stats::by function produces list-like objects, which can be converted to arrays or data frames

Examples

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))
}



Pmisc documentation built on Feb. 14, 2024, 3 a.m.