更改 R 中 t 检验(by() 内部)的置信度

Change confidence level in t test (inside of by()) in R

我需要在 by()

中更改 t.test 中的置信度值
res<-by(HUS[,1], HUS$air.conditioning, FUN=t.test)

哪里可以提供conf.level?

使用anonymous/lamdba函数(function(x)

res <- by(HUS[,1], HUS$air.conditioning, FUN = 
         function(x) t.test(x, conf.level = 0.90))

或指定命名参数

res <- by(HUS[,1], HUS$air.conditioning, FUN=t.test, conf.level = 0.90)

注意:指定命名参数可能不适用于所有函数,例如ave


检查可重现的例子

res1 <- by(mtcars[, "mpg"], mtcars$cyl, FUN = t.test, conf.level = 0.90)
res2 <- by(mtcars[, "mpg"], mtcars$cyl, FUN = function(x) t.test(x,  conf.level = 0.90))
> res1 <- lapply(res1, function(x) {x$data.name <- "x"; x})
> all.equal(res1, res2, check.attributes = FALSE)
[1] TRUE