table()函数--R语言

函数功能:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值