Learn R Programming

lava (version 1.8.0)

By: Apply a Function to a Data Frame Split by Factors

Description

Apply a Function to a Data Frame Split by Factors

Usage

By(x, INDICES, FUN, COLUMNS, array = FALSE, ...)

Arguments

x

Data frame

INDICES

Indices (vector or list of indices, vector of column names, or formula of column names)

FUN

A function to be applied to data frame subsets of 'data'.

COLUMNS

(Optional) subset of columns of x to work on

array

if TRUE an array/matrix is always returned

...

Additional arguments to lower-level functions

Author

Klaus K. Holst

Details

Simple wrapper of the 'by' function

Examples

Run this code
By(datasets::CO2,~Treatment+Type,colMeans,~conc)
By(datasets::CO2,~Treatment+Type,colMeans,~conc+uptake)

Run the code above in your browser using DataLab