20190428-R语言循环函数aggregate、by

2019-04-28  本文已影响0人  天空的小白

-Usage
aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE)
与tapply类似,但是x可以为data.frame或矩阵;
-Arguments
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.
-Example


testDF
Vby1
by2
aggregate

-Usage
by(data, INDICES, FUN, ..., simplify = TRUE);
-Example
将warpbreaks的一二列,根据tension这一列的(L、M、H)运行summary

warpbreaks
by

aggregate与by的区别:aggregate是对x的每一列分别根据因子进行分组计算,而by是根据因子将data整个分成几个小的data.frame,然后进行运算;

上一篇 下一篇

猜你喜欢

热点阅读