Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

Details

Simple wrapper of the 'by' function

Author(s)

Klaus K. Holst

Examples

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

lava

Latent Variable Models

v1.6.10
GPL-3
Authors
Klaus K. Holst [aut, cre], Brice Ozenne [ctb], Thomas Gerds [ctb]
Initial release
2021-09-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.