table可统计数据的频数
tapply可根据因子、向量和要计算的函数计算
> class<-c(1,2,3,2,1,2,1,3)
> class
[1] 1 2 3
> c(81,65,72,88,73,91,56,90)->student
> class
[1] 1 2 3 2 1 2 1 3
>factor(class)->class
> tapply(student,class,mean)
1 2 3
70.00000 81.33333 81.00000
> tapply(student,class,min)
1 2 3
56 65 72
> tapply(student,class,max)
1 2 3
81 91 90
> table(class)
class
1 2 3
3 3 2
>
Apply a Function Over a Ragged Array
Description
Apply a function to each cell of a ragged array, that is to each (non-empty) group of values given by a unique combination of the levels of certain factors.
Usage
tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE)
Arguments
X |
an atomic object, typically a vector.
|
INDEX |
list of factors, each of same length as X . The elements are coerced to factors by as.factor .
|
FUN |
the function to be applied, or NULL . In the case of functions like + , %*% , etc., the function name must be backquoted or quoted. If FUN is NULL , tapply returns a vector which can be used to subscript the multi-way array tapply normally produces.
|
... |
optional arguments to FUN : the Note section.
|
simplify |
If FALSE , tapply always returns an array of mode "list" . If TRUE (the default), then if FUN always returns a scalar, tapply returns an array with the mode of the scalar.
|
Value
If FUN
is not NULL
, it is passed to match.fun
, and hence it can be a function or a symbol or character string naming a function.
When FUN
is present, tapply
calls FUN
for each cell that has any data in it. If FUN
returns a single atomic value for each such cell (e.g., functions mean
or var
) and when simplify
is TRUE
, tapply
returns a multi-way array containing the values, and NA
for the empty cells. The array has the same number of dimensions as INDEX
has components; the number of levels in a dimension is the number of levels (nlevels()
) in the corresponding component of INDEX
. Note that if the return value has a class (e.g. an object of class "Date"
) the class is discarded.
Note that contrary to S, simplify = TRUE
always returns an array, possibly 1-dimensional.
If FUN
does not return a single atomic value, tapply
returns an array of mode list
whose components are the values of the individual calls to FUN
, i.e., the result is a list with a dim
attribute.
When there is an array answer, its dimnames
are named by the names of INDEX
and are based on the levels of the grouping factors (possibly after coercion).
For a list result, the elements corresponding to empty cells are NULL
.
Note
Optional arguments to FUN
supplied by the ...
argument are not divided into cells. It is therefore inappropriate for FUN
to expect additional arguments with the same length as X
.
References
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
See Also
the convenience functions by
and aggregate
(using tapply
); apply
, lapply
with its versions sapply
and mapply
.
Examples
require(stats)
groups <- as.factor(rbinom(32, n = 5, prob = 0.4))
tapply(groups, groups, length) #- is almost the same as
table(groups)
## contingency table from data.frame : array with named dimnames
tapply(warpbreaks$breaks, warpbreaks[,-1], sum)
tapply(warpbreaks$breaks, warpbreaks[, 3, drop = FALSE], sum)
n <- 17; fac <- factor(rep(1:3, length = n), levels = 1:5)
table(fac)
tapply(1:n, fac, sum)
tapply(1:n, fac, sum, simplify = FALSE)
tapply(1:n, fac, range)
tapply(1:n, fac, quantile)
## example of ... argument: find quarterly means
tapply(presidents, cycle(presidents), mean, na.rm = TRUE)
ind <- list(c(1, 2, 2), c("A", "A", "B"))
table(ind)
tapply(1:3, ind) #-> the split vector
tapply(1:3, ind, sum)
分享到:
相关推荐
赠送jar包:flink-table-planner-blink_2.11-1.12.7.jar; 赠送原API文档:flink-table-planner-blink_2.11-1.12.7-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用
赠送jar包:flink-table-planner-blink_2.11-1.13.2.jar; 赠送原API文档:flink-table-planner-blink_2.11-1.13.2-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用
赠送jar包:flink-table-api-java-bridge_2.11-1.12.7.jar; 赠送原API文档:flink-table-api-java-bridge_2.11-1.12.7-javadoc.jar; 赠送源代码:flink-...人性化翻译,文档中的代码和结构保持不变,注释和说明精
改版uni-table插件功能,新增单击行事件、单击某td事件、单独修改某td的字体颜色;选中行样式修改。主要修改文件uni-tr、uni-td;
赠送jar包:flink-table-planner_2.12-1.14.3.jar 赠送原API文档:flink-table-planner_2.12-1.14.3-javadoc.jar ...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
赠送jar包:flink-table-common-1.12.7.jar; 赠送原API文档:flink-table-common-1.12.7-javadoc.jar; 赠送源代码:flink-table-common...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
赠送jar包:flink-table-runtime-blink_2.11-1.10.0.jar; 赠送原API文档:flink-table-runtime-blink_2.11-1.10.0-javadoc.jar; 赠送源代码:flink-table-...人性化翻译,文档中的代码和结构保持不变,注释和说明
赠送jar包:flink-table-api-java-bridge_2.11-1.13.2.jar; 赠送原API文档:flink-table-api-java-bridge_2.11-1.13.2-javadoc.jar; 赠送源代码:flink-table-api-java-bridge_2.11-1.13.2-sources.jar; 赠送...
赠送jar包:flink-table-planner-blink_2.11-1.13.2.jar; 赠送原API文档:flink-table-planner-blink_2.11-1.13.2-javadoc.jar; 赠送源代码:flink-table-...人性化翻译,文档中的代码和结构保持不变,注释和说明精准
赠送jar包:flink-table-planner-blink_2.11-1.10.0.jar; 赠送原API文档:flink-table-planner-blink_2.11-1.10.0-javadoc.jar; 赠送源代码:flink-table-...人性化翻译,文档中的代码和结构保持不变,注释和说明
本文实例讲述了bootstrap-table后端分页功能。分享给大家供大家参考,具体如下: 使用bootstrap-table实现后台分页 插件资源点击此处本站下载。 引用以下css <link rel="stylesheet" href="../plugins/...
赠送jar包:flink-table-runtime-blink_2.11-1.12.7.jar; 赠送原API文档:flink-table-runtime-blink_2.11-1.12.7-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用
赠送jar包:flink-table-api-java-bridge_2.11-1.10.0.jar; 赠送原API文档:flink-table-api-java-bridge_2.11-1.10.0-javadoc.jar; 赠送源代码:flink-table-api-java-bridge_2.11-1.10.0-sources.jar; 赠送...
赠送jar包:flink-table-runtime-blink_2.11-1.13.2.jar; 赠送原API文档:flink-table-runtime-blink_2.11-1.13.2-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用
赠送jar包:flink-table-api-java-1.14.3.jar 赠送原API文档:flink-table-api-java-1.14.3-javadoc.jar 赠送源代码:flink-table-api-...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
赠送jar包:flink-table-api-java-bridge_2.12-1.14.3.jar; 赠送原API文档:flink-table-api-java-bridge_2.12-1.14.3-javadoc.jar; 赠送源代码:flink-table-api-java-bridge_2.12-1.14.3-sources.jar; 赠送...
bootstrap-table实现 行拖拽 插件 jquery.tablednd.js bootstrap-table-reorder-rows.js bootstrap-table-reorder-rows.css
赠送jar包:flink-table-planner_2.12-1.14.3.jar; 赠送原API文档:flink-table-planner_2.12-1.14.3-...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。
基于bootstrap-table 实现 右侧列固定,也可以针对左侧列固定,针对操作列使用起来非常方便,引用jquery、bootstrap-table-fixed 样式和js文件后,可以随意设置,灵活。 fixedColumns: true,//fixedtNumber:2, //...
赠送jar包:flink-table-api-java-bridge_2.12-1.14.3.jar 赠送原API文档:flink-table-api-java-bridge_2.12-1.14.3-javadoc.jar ...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。