Learn R Programming

SciencesPo (version 1.3.5)

as.data.frame.by: Convert the results of by() to a data.frame.

Description

Converts the results of by() to a data.frame if possible, (reducing dimensionality and adding repetition as necessary)

Usage

## S3 method for class 'by':
as.data.frame(x, row.names = NULL, optional = FALSE,
  colnames = paste("IDX", seq(length(dim(x))), sep = ""), na.rm = TRUE, ...)

Arguments

x
The by object
row.names
Names of the rows. If NULL, function tries guessing them.
optional
Ignored.
colnames
Names of columns
na.rm
Remove NAs or not.
...
Pass-alongs.

Value

  • A data.frame.

Examples

Run this code
sex    <- factor(rbinom(1:1000, 1, 0.5), labels=c("male" , "female"));
age    <- sample(1:100, 1000, rep=TRUE);
weight <- factor(rbinom(1:1000, 2, 0.6), labels=c("light", "middle", "heavy"))
by(age, sex, mean)

Run the code above in your browser using DataLab