table()函数

您所在的位置:网站首页 r语言中frame含义 table()函数

table()函数

2023-08-13 03:02| 来源: 网络整理| 查看: 265

函数功能:

table uses the cross-classifying factors to build a contingency table of the counts at each combination of factor levels.

table函数构建列联表,统计每个因子的频数

函数语法:

table(..., exclude = if (useNA == "no") c(NA, NaN), useNA = c("no", "ifany", "always"), dnn = list.names(...), deparse.level = 1)

函数参数:

1. … ... one or more objects which can be interpreted as factors (including character strings), or a list (or data frame) whose components can be so interpreted.

一个或者多个可以解释为因子或者字符串的对象;或者可以被解释成分的列表

2. exclude exclude levels to remove for all factors in .... If it does not contain NA and useNA is not specified, it implies useNA = "ifany".

不做统计的因子水平,若要统计其中的NA值,需要设置exclude参数为NULL 在这里插入图片描述 在这里插入图片描述 原始通过透视表得到的数据如下所示(部分展示): 在这里插入图片描述 当不指定exclude,默认不包含空值NA 在这里插入图片描述 当指定exclude ,则去除exclude中的因素 在这里插入图片描述

在这里插入图片描述 在这里插入图片描述

3. useNA useNA whether to include NA values in the table

当useNA 取值为’no’,不统计NA频数,当取值为’ifany’,'always’统计NA频数 在这里插入图片描述 当useNA =‘always’ 在这里插入图片描述 在这里插入图片描述 当useNA=‘ifany’,只有正数的列联表值会显示 在这里插入图片描述

在这里插入图片描述 当useNA=‘no’,但exclude已指定排出因素为‘不详’,因子NA列依然存在 在这里插入图片描述 总结:当仅指定NA的处理,可以使用useNA参数;当指定多个因素的处理可以使用exclude.

4. dnn dnn the names to be given to the dimensions in the result (the dimnames names)

在这里插入图片描述

5.deparse.level deparse.level controls how the default dnn is constructed


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3