我在下面有一个示例数据框。
example.df <- data.frame(
species = sample(c("primate", "non-primate"), 50, replace = TRUE),
treated = sample(c("Yes", "No"), 50, replace = TRUE),
gender = sample(c("male", "female"), 50, replace = TRUE),
var1 = rnorm(50, 100, 5), resp=rnorm(50, 10,5), value1 = rnorm (50, 25, 5))
我想先分组treated
,然后遍历数据中的所有数字变量以使用作为解释变量执行 dunn 测试(pairw.kw
来自asbio
包) ,提取数据框对象并将列和子列表中的列绑定到一个新的数据框对象。species
summary
yes
no
我已经在这里和这里使用部分“整洁”的方法获得了部分解决方案,效果很好。我只是在寻找更优雅的 tidyverse 解决方案,以帮助我学习成为更好的 R 用户。
任何帮助表示赞赏。
编辑:这是我从部分“整洁”解决方案中的代码获得的输出。
structure(list(var1.Diff = structure(1:2, .Label = c("-7.05229",
"-2.25"), class = "factor"), var1.Lower = structure(1:2, .Label =
c("-13.23198",
"-8.25114"), class = "factor"), var1.Upper = structure(1:2, .Label =
c("-0.87259",
"3.75114"), class = "factor"), var1.Decision = structure(1:2, .Label =
c("Reject H0",
"FTR H0"), class = "factor"), var1.Adj..P.value = structure(1:2, .Label =
c("0.025305",
"0.462433"), class = "factor"), resp.Diff = structure(1:2, .Label =
c("1.10458",
"0"), class = "factor"), resp.Lower = structure(1:2, .Label = c("-5.07512",
"-6.00114"), class = "factor"), resp.Upper = structure(1:2, .Label =
c("7.28427",
"6.00114"), class = "factor"), resp.Decision = structure(c(1L,
1L), .Label = "FTR H0", class = "factor"), resp.Adj..P.value =
structure(1:2, .Label = c("0.726092",
"1"), class = "factor"), effect.Diff = structure(1:2, .Label =
c("-1.27451",
"-0.5625"), class = "factor"), effect.Lower = structure(1:2, .Label =
c("-7.4542",
"-6.56364"), class = "factor"), effect.Upper = structure(1:2, .Label =
c("4.90518",
"5.43864"), class = "factor"), effect.Decision = structure(c(1L,
1L), .Label = "FTR H0", class = "factor"), effect.Adj..P.value =
structure(1:2, .Label = c("0.686047",
"0.85424"), class = "factor")), row.names = c("No", "Yes"), class =
"data.frame")