group_f: apply a function by group and return results of the same...

View source: R/apply_family.R

group_fR Documentation

apply a function by group and return results of the same length to the data

Description

apply a function by group and return results of the same length to the data

Usage

group_f(x, group, f, ...)

Arguments

x

same as tapply

group

a factor

f

function to be applied

...

optional arguments passed to the function

Examples

set.seed(123)
data <- data.frame(y = 1:10, g = gl(2,5, labels = c("1-5", "6-10")))
data <- data[sample(nrow(data)), ]
data$mean  <- with(data, group_f(y, g, mean))
data$min  <- with(data, group_f(y, g, min))
data$max  <- with(data, group_f(y, g, max))


lbraglia/lbmisc documentation built on March 28, 2024, 10:03 a.m.