所以我有这个数据并试图完成kruskal.test()
一个包含数据框的列表
df_list <- list(
`1.3.A` =
tibble::tribble(
~Person, ~Height, ~Weight,
"Alex", 175L, 75L,
"Gerard", 180L, 85L,
"Clyde", 179L, 79L,
"Alex", 175L, 75L,
"Gerard", 180L, 85L,
"Clyde", 179L, 79L
),
`2.2.A` =
tibble::tribble(
~Person, ~Height, ~Weight,
"Alex", 175L, 75L,
"Gerard", 180L, 85L,
"Clyde", 179L, 79L,
"Alex", 175L, 75L,
"Gerard", 180L, 85L,
"Clyde", 179L, 79L
),
`1.1.B` =
tibble::tribble(
~Person, ~Height, ~Weight,
"Alex", 175L, 75L,
"Gerard", 180L, 85L,
"Clyde", 179L, 79L,
"Alex", 175L, 75L,
"Gerard", 180L, 85L,
"Clyde", 179L, 79L
)
)
我试图kruskal.test
在这 3 个数据帧上执行,但在试图找到解决方案数小时后失败了。我是 R 的新手。
失败的尝试是:
snake <- function(i){
kruskal.test(df$Height ~ df$Person, data = i)
}
snail <- lapply(df_list, "[[", snake)
df_list %>% kruskal.test(df$Height ~ df$Person)
sapply(df_list, function(i) { kruskal.test(df$Height ~ df$Person, data = i)})
Map(function(x) kruskal.test(Height ~ Person), get(df_list))
Map(function(df_list, .f(kruskal.test(Height ~ Person)))
lapply(mget(df_list), function(x) kruskal.test(Height ~ Person))
bunny <- df_list %>%
kruskal_test(df$Height ~ Person, data = .)
摘要:我正在尝试kruskal.test()
处理一组包含数据框的列表。如何传递公式lapply()
或在列表中的每个数据框中Map()
运行?kruskal.test()