从R中的Tukey HSD中提取数据

时间:2013-02-18 15:58:01

标签: r structure extract

考虑下面的玩具代码(纯粹是说明性的):

y <- data.frame(matrix(c(11,12,13,14,113,124,215,219),nrow=4));
y[,2] <- factor(y[,2]);
aov.result <- aov(y$X1 ~ y$X2, data=y);
thsd.result <- TukeyHSD(aov.result); # Produces NaNs but nevermind
fix(thsd.result)

最后一个命令(fix)显示thsd.result对象是一个包含列表和嵌套结构的结构:

structure(list(`df$X2` = structure(c(1, 2, 3, 1, 2, 1, NaN, NaN, 
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 
NaN, NaN, NaN), .Dim = c(6L, 4L), .Dimnames = list(c("124-113", 
"215-113", "219-113", "215-124", "219-124", "219-215"), c("diff", 
"lwr", "upr", "p adj")))), .Names = "df$X2", class = c("multicomp", 
"TukeyHSD"), orig.call = quote(aov(formula = df$X1 ~ df$X2, data = df)), conf.level =     
0.95, ordered = FALSE);

我的问题是:我将如何访问此结构?即例如,我将如何获得由对组成的.Dimnames?

1 个答案:

答案 0 :(得分:0)

你的意思是这样的:

dimnames(thsd.result[[1]])

和此:

> rownames(thsd.result[[1]])
[1] "124-113" "215-113" "219-113" "215-124" "219-124" "219-215"
> colnames(thsd.result[[1]])
[1] "diff"  "lwr"   "upr"   "p adj"

获取结果只需使用[[]]访问它。

查看打印的结果:

thsd.result[[1]]thsd.result[[1]][,1]