Learn R Programming

erpR (version 0.2.0)

named.agg: aggregate and keep the original names

Description

A wrapper of the aggregate function. Data are provided as a formula and the original names are kept in the returned data.frame.

Usage

named.agg(formula, data, FUN, ..., subset, na.action = na.omit)

Arguments

formula
a formula, such as y ~ x or cbind(y1, y2) ~ x1 + x2, where the y variables are numeric data to be split into groups according to the grouping x variables (typically factors).
data
the data.frame to be aggregated.
FUN
a function to compute the summary statistics which can be applied to all data subsets.
subset
an optional vector specifying a subset of observations to be used.
na.action
a function which indicates what should happen when the data contain NA values. The default is to ignore missing values in the given variables.
...
further arguments passed to or used by methods.

Value

For the data frame method, teh function returns a data frame with columns corresponding to the grouping variables in the right part of the formula, followed by aggregated columns from the left part of the formula. The names of the variables remain the same as in the original data frame.

See Also

aggregate

Examples

Run this code

data(ERPsets)

datall=erp.mean(base = "Exp1_word_subj", numbers = 1:20, 
win.ini = 400, win.end = 600, erplist=ERPsets, startmsec= -200, 
endmsec = 1500, format="long", name.dep="Ampl")

datagg=named.agg(Ampl~electrode+Subject, datall, FUN=mean)

Run the code above in your browser using DataLab