aggregate()函数--R语言

本文详细介绍了R语言中aggregate函数的使用方法,包括其如何将数据拆分成子集、为每个子集计算摘要统计信息并以方便的形式返回结果。文章还解释了函数的语法和各个参数的具体含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值