aggregate()函数--R语言

1.函数功能

Splits the data into subsets, computes summary statistics for each, 
and returns the result in a convenient form.

将数据拆分为子集,为每个子集计算摘要统计信息,然后以方便的形式返回结果。

2.函数语法

aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE)

3. 函数参数

3.1 x

x	
an R object.

R对象

3.2 by

by	
a list of grouping elements, each as long as the variables in the data frame x. 
The elements are coerced to factors before use.

分组元素的列表,每个与数据框x中的变量长度相同。 使用之前,将这些元素强制转换为因子。

3.3 FUN

FUN	
a function to compute the summary statistics which can be applied to all data subsets.

计算汇总统计信息的函数,FUN(function)

3.4 simplify

simplify	
a logical indicating whether results should be simplified to a vector or matrix if possible.

逻辑值,表明是否应将结果简化为向量或矩阵。

3.5 drop

drop	
a logical indicating whether to drop unused combinations of grouping values. 
The non-default case drop=FALSE has been amended for R 3.5.0 to drop unused combinations.

逻辑值,表明是否删除未使用的分组值组合的逻辑。默认为TRUE

aggregate.data.frame is the data frame method. If x is not a data frame, it is coerced to one, 
which must have a non-zero number of rows. 
Then, each of the variables (columns) in x is split into subsets of cases (rows) of identical combinations of the components of by, 
and FUN is applied to each such subset with further arguments in ... passed to it. 
The result is reformatted into a data frame containing the variables in by and x.

aggregate.data.frame是数据框方法,若x不是数据框,将其转换为数据框,该数据库的行数不为0.
然后,将x中的每个变量(列)划分为by成分完全相同的情况(行)的子集,然后将FUN应用于每个此类子集,并在…中传递进一步的参数。将结果重新格式化为包含by和x中变量的数据框。

aggregate()函数--R语言_第1张图片

aggregate()函数--R语言_第2张图片

原文链接: aggregate

你可能感兴趣的:(R)