2

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

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)

最后一个命令(修复)显示 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?

4

1 回答 1

1

你的意思是这样的:

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]

于 2013-02-18T16:01:05.943 回答