mydata<-structure(list(Weight = c(66.2, 65.2, 69.8, 63.4, 67.4, 66.3,
63.8, 67.8, 66.7, 66.2, 61.9, 66.9, 69.4, 60.8, 64.1, 62.8, 62.5,
60.9, 61.3, 67.8), Age = c(68, 67, 65, 65, 63, 64, 68, 65, 65,
71, 64, 65, 68, 61, 65, 62, 60, 66, 62, 58),
Sex = c("H", "H",
"H", "H", "H", "H", "F", "F", "F", "F", "H", "H", "H", "F", "F",
"F", "F", "F", "F", "F"),
Group = c("G1", "G1", "G1", "G1",
"G1", "G1", "G1", "G1", "G1", "G1", "G2", "G2", "G2", "G2", "G2",
"G2", "G2", "G2", "G2", "G2")), row.names = c(NA, -20L),
class = "data.frame")
我想通过手动创建表格来总结我的数据。我的目标是比较两组之间的变量。我不知道有任何软件可以让我以表格格式获得均值和p值差异的置信区间。我必须用Rmarkdown以word格式导出数据,所以我应该以表格格式导出数据。
我创建的所有参数如下所示:
confInt<-paste(round(t.test(mydata$Weight~mydata$Group)$conf.int[1],2),
round(t.test(mydata$Weight~mydata$Group)$conf.int[2],2),sep = ";")
p.value<-round(t.test(mydata$Weight~mydata$Group)$p.value,3)
mean1<-mean(mydata$Weight[mydata$Group=="G1"])
mean2<-mean(mydata$Weight[mydata$Group=="G2"])
mean_diff<-(mean(mydata$Weight[mydata$Group=="G1"])-
mean(mydata$Weight[mydata$Group=="G2"]))
我们的目标是通过一个循环或一个函数为每个数值变量创建这些参数。
然后通过rowbind
绑定每个变量的统计信息
1条答案
按热度按时间bhmjp9jg1#
我们可以创建一个函数,它接受数据
mydata
、数值列col
和分组列group
:然后我们可以使用以下代码来提取数字列的名称:
并通过for循环获得摘要输出:
或使用
do.call
+lapply