xtabs(Matrix)
xtabs()所属R语言包:Matrix
Cross Tabulation, Optionally Sparse
交叉制表,可选稀疏
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Create a contingency table from cross-classifying factors, usually contained in a data frame, using a formula interface.
从跨分类的因素,创造一个应急表,通常包含在一个数据框,使用一个公式界面。
This is a fully compatible extension of the standard stats package xtabs() function with the added option to produce a sparse matrix result via sparse = TRUE.
这是一个完全兼容的扩展标准stats包xtabs()功能与选项产生稀疏矩阵结果通过sparse = TRUE。
用法----------Usage----------
xtabs(formula = ~., data = parent.frame(), subset, sparse = FALSE, na.action,
exclude = c(NA, NaN), drop.unused.levels = FALSE)
参数----------Arguments----------
参数:formula
a formula object with the cross-classifying variables (separated by +) on the right hand side (or an object which can be coerced to a formula). Interactions are not allowed. On the left hand side, one may optionally give a vector or a matrix of counts; in the latter case, the columns are interpreted as corresponding to the levels of a variable. This is useful if the data have already been tabulated, see the examples below.
与交叉分类变量的右侧(+分隔)(或对象可以强制转换为一个公式)公式对象。不允许相互作用。左手边,可以选择给一个向量或矩阵的计数;在后一种情况下,列相应的解释变量的水平。这是有用的,如果数据已经表,请参阅下面的例子。
参数:data
an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).
一个可选的矩阵或数据框(或类似:看到model.frame)包含公式formula的变量。默认情况下采取的变量从environment(formula)。
参数:subset
an optional vector specifying a subset of observations to be used.
一个可选的向量,指定要使用的意见的一个子集。
参数:sparse
logical specifying if the result should be a sparse matrix, i.e., inheriting from sparseMatrix. Only works for two factors (since there are no higher-order sparse array classes yet).
逻辑指定的结果应该是一个稀疏矩阵,即,从sparseMatrix继承。仅适用于两个因素(因为有没有高阶稀疏数组类)。
参数:na.action
a function which indicates what should happen when the data contain NAs.
一个函数,它表示数据时,包含NA的,应该发生什么。
参数:exclude
a vector of values to be excluded when forming the set of levels of the classifying factors.
形成一套分级因素的水平时,要排除一个值的向量。
参数:drop.unused.levels
a logical indicating whether to drop unused levels in the classifying factors. If this is FALSE and there are unused levels, the table will contain zero marginals, and a subsequent chi-squared test for independence of the factors will not work.
逻辑表示未使用的水平是否下降的分类因素。如果这是FALSE“有未使用的水平,该表将包含零的边缘人,随后因素的独立性卡方测试,将无法正常工作。
Details
详情----------Details----------
For (non-sparse) xtabs results, there is a summary method for contingency table objects created by table or xtabs, which gives basic information and performs a chi-squared test for independence of factors (note that the function chisq.test currently only handles 2-d tables).
(非稀疏)xtabs的结果,有一个summary应急table或xtabs,它提供了基本的信息和执行卡方表创建的对象的方法测试的独立因素(注意函数chisq.test目前仅处理2-D表)。
If a left hand side is given in formula, its entries are simply summed over the cells corresponding to the right hand side; this also works if the lhs does not give counts.
如果左边是在formula定,简单地概括其作品在右侧相应的单元,这也可以,如果在LHS不计数。
值----------Value----------
By default, when sparse=FALSE, a contingency table in array representation of S3 class c("xtabs", "table"), with a "call" attribute storing the matched call.
默认情况下,当sparse=FALSE,c("xtabs", "table")属性存储匹配的呼叫数组表示的S3类"call",在应急表。
When sparse=TRUE, a sparse numeric matrix, specifically an object of S4 class dgTMatrix.
当sparse=TRUE,稀疏矩阵数字,具体对象的S4级dgTMatrix。
参见----------See Also----------
The stats package version xtabs and its references.
stats包的版本xtabs和其参考。
举例----------Examples----------
## See for non-sparse examples:[#见非稀疏的例子:]
example(xtabs, package = "stats")
## similar to "nlme"s 'ergoStool' :[#类似的“nlme”S“ergoStool”:]
d.ergo <- data.frame(Type = paste("T", rep(1:4, 9*4), sep=""),
Subj = gl(9,4, 36*4))
xtabs(~ Type + Subj, data=d.ergo) # 4 replicates each[4个重复每个]
set.seed(15) # a subset of cases:[情况下的一个子集:]
xtabs(~ Type + Subj, data=d.ergo[sample(36, 10),], sparse=TRUE)
## Hypothetical two level setup:[#假设两个级别设置:]
inner <- factor(sample(letters[1:25], 100, replace = TRUE))
inout <- factor(sample(LETTERS[1:5], 25, replace = TRUE))
fr <- data.frame(inner = inner, outer = inout[as.integer(inner)])
xtabs(~ inner + outer, fr, sparse = TRUE)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|