集合在R中 [英] Group by aggregate in R
问题描述
我有一个CSV文件,具有以下数据:
ID名称批次标记成绩
pre>
1 A 2010 43 C
2 B 2011 88 A
3 C 2011 89 A
4 D 2010 47 C
5 E 2011 82 A
使用R语言,我需要对每个批次的学生总数进行总结。
我可以使用什么作为汇总功能在R中不再可用?我真的不知道如何开始请帮助。解决方案聚合 / p>
with(nameOfYourDataFrame,aggregate(X = Marks,by = list(Batch),FUN = sum))
聚合有三个参数:
X :连续变量,以及什么传递给函数,FUN
由:一个或多个离散变量),其值确定函数FUN评估
FUN 的分区:该函数是传递连续变量X,并且为
中为参数传递的每个离散变量的每个值(或级别)计算一个结果。 >从上下文中不清楚你有什么汇总功能;在任何情况下,如果它不是总和,则任何内置的,例如意味着或用户定义的fn将工作
包 Hmisc 中的功能总结是另一个功能,做同样的事情。
I have a CSV file with the following data:
ID Name Batch Marks Grade 1 A 2010 43 C 2 B 2011 88 A 3 C 2011 89 A 4 D 2010 47 C 5 E 2011 82 A
Using R language, I need to take aggregate of the marks of students for the individual batches. What can I use as Rollup function is not available any more in R? I really dont know how to start. Please help.
解决方案aggregate is a good choice here.
with(nameOfYourDataFrame, aggregate(X=Marks, by=list(Batch), FUN=sum))
aggregate takes three arguments:
X: the continuous variable, and what's passed to the function, FUN
by: one or more discrete variables (aka factors), the values of which determine the 'partitions' that the function, FUN, evaluates
FUN: the function which is passed the continuous variable, X, and calculates one result for each value (or level) for each discrete variable passed in for the parameter, by
not sure from context what rollup function you have in mind; in any event, if it is not sum, then any built-in, eg mean or user-defined fn will work
the function summarize in the package Hmisc is another function to do the same thing.
这篇关于集合在R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!