簡體   English   中英

在R中`summary(aov)`的輸出中添加一列?

[英]Adding a column to the output of `summary(aov)` in R?

我想知道是否有可能在summary(aov)給定的輸出中添加標題列?

例如,在下面的summary(aov) ,我們可以添加一個標題為aa的列:

aa = c(4.391098, 12.105541,  0.537330,  6.088639,  1.361073)

# add `aa` above to the right-most column of summary output below:

fit <- summary(aov(yield ~ block + N * P + K, data = npk))

我嘗試了以下操作但未成功:

fit[[2]] <- aa

我們可以使用cbind更新提取的list元素

fit[[1]] <- cbind(fit[[1]],aa = c(aa, NA)) 

但是,這將刪除anova類,這將是一個data.frame

如果要打印具有重要意義的星星,則不能將新列添加為最后一列。 最后一列必須是p值:

aa = c(4.391098, 12.105541,  0.537330,  6.088639,  1.361073)

# add `aa` above to the right-most column of summary output below:

fit <- summary(aov(yield ~ block + N * P + K, data = npk))

fit[[1]]$aa <- c(aa, NA) 
fit[[1]] <- fit[[1]][c(1, 2, 3, 6, 4, 5)]

fit
#            Df Sum Sq Mean Sq     aa F value  Pr(>F)   
#block        5  343.3   68.66  4.391   4.391 0.01295 * 
#N            1  189.3  189.28 12.106  12.106 0.00368 **
#P            1    8.4    8.40  0.537   0.537 0.47564   
#K            1   95.2   95.20  6.089   6.089 0.02711 * 
#N:P          1   21.3   21.28  1.361   1.361 0.26284   
#Residuals   14  218.9   15.64                          
#---
#Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM