本文介绍了将两个统计表的结果合并到R中的一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题的继续比较各组之间的Mann-Whitney检验,我决定创建一个新主题.

In continuation of this issue comparison Mann-Whitney test between groups, I decided to create a new topic.

Rui Barradas的解决方案帮助我计算了1-2组和1-3组的Mann-Whitney.

Solution of Rui Barradas helped me calculate Mann-Whitney for group 1-2 and 1-3.

lst <- split(mydat, mydat$group)
lapply(lst[-1], function(DF) wilcox.test(DF$var, lst[[1]]$var, exact = FALSE))

现在我要获取描述性统计信息.我用library:psych

So now i want get the descriptive statistics. I use library:psych

describeBy(mydat$var,mydat$group)

所以我得到以下输出

group: 1
   vars n mean   sd median trimmed  mad min max range skew kurtosis   se
X1    1 4 23.5 0.58   23.5    23.5 0.74  23  24     1    0    -2.44 0.29
--------------------------------------------------------------------------------------
group: 2
   vars n mean   sd median trimmed  mad min max range skew kurtosis   se
X1    1 4 23.5 0.58   23.5    23.5 0.74  23  24     1    0    -2.44 0.29
--------------------------------------------------------------------------------------
group: 3
   vars n mean   sd median trimmed  mad min max range skew kurtosis   se
X1    1 4 23.5 0.58   23.5    23.5 0.74  23  24     1    0    -2.44 0.29

这很不方便.我只需要每组wilcox.test的均值,标准差,中位数和p值​​.

It is inconvenient.I need only for each group mean,sd,median and p-value of wilcox.test.

I.E.我想要这些输出

I.E. i want these output

       mean    sd     median      p-value
group1  23,5    0,58    23,5    -
group2  23,5    0,58    23,5    1
group3  23,5    0,58    23,5    1

我该如何表演?

structure(list(`1` = structure(list(vars = 1, n = 4, mean = 23.5,
    sd = 0.577350269189626, median = 23.5, trimmed = 23.5, mad = 0.7413,
    min = 23, max = 24, range = 1, skew = 0, kurtosis = -2.4375,
    se = 0.288675134594813), .Names = c("vars", "n", "mean",
"sd", "median", "trimmed", "mad", "min", "max", "range", "skew",
"kurtosis", "se"), row.names = "X1", class = c("psych", "describe",
"data.frame")), `2` = structure(list(vars = 1, n = 4, mean = 23.5,
    sd = 0.577350269189626, median = 23.5, trimmed = 23.5, mad = 0.7413,
    min = 23, max = 24, range = 1, skew = 0, kurtosis = -2.4375,
    se = 0.288675134594813), .Names = c("vars", "n", "mean",
"sd", "median", "trimmed", "mad", "min", "max", "range", "skew",
"kurtosis", "se"), row.names = "X1", class = c("psych", "describe",
"data.frame")), `3` = structure(list(vars = 1, n = 4, mean = 23.5,
    sd = 0.577350269189626, median = 23.5, trimmed = 23.5, mad = 0.7413,
    min = 23, max = 24, range = 1, skew = 0, kurtosis = -2.4375,
    se = 0.288675134594813), .Names = c("vars", "n", "mean",
"sd", "median", "trimmed", "mad", "min", "max", "range", "skew",
"kurtosis", "se"), row.names = "X1", class = c("psych", "describe",
"data.frame"))), .Dim = 3L, .Dimnames = structure(list(group = c("1",
"2", "3")), .Names = "group"), call = by.default(data = x, INDICES = group,
    FUN = describe, type = type), class = c("psych", "describeBy"
))

推荐答案

将数据发布到问题的链接中,并使用如上所述的split指令,以下内容将产生所需的输出.

With the data posted in the linked to question and with the split instruction as above, the following will produce the desired output.

我重复测试以将其结果分配给wt_list.

I repeat the tests in order to assign their results to wt_list.

wt_list <- lapply(lst[-1], function(DF) wilcox.test(DF$var, lst[[1]]$var, exact = FALSE))

mu <- tapply(mydat$var, mydat$group, mean)
s  <- tapply(mydat$var, mydat$group, sd)
md <- tapply(mydat$var, mydat$group, median)

pval <- c(NA, sapply(wt_list, '[[', "p.value"))

df_smry <- data.frame(mean = mu, sd = s, median = md, p.value = pval)

df_smry
#  mean        sd median p.value
#1 23.5 0.5773503   23.5      NA
#2 23.5 0.5773503   23.5       1
#3 23.5 0.5773503   23.5       1

这篇关于将两个统计表的结果合并到R中的一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:44