我有一个函数可以使用 wilcoxon 测试比较每组中的列。功能:
group.leb=c(1,2)
z <- c(2,3,4)
v <- 2
s <- sapply(z,'+',v)
combination <- mapply(c,z,s,SIMPLIFY = F)
wilcox.fun <- function(dat) {
do.call(rbind, lapply(combination, function(x) {
test <- wilcox.test(dat[[x[1]]], dat[[x[2]]], paired=FALSE)
data.frame(Test = sprintf('Group %s by Group %s', x[1], x[2]),
W = round(test$statistic,4),
p = test$p.value)
}))
}
result <- purrr::map_df(split(data, data$group), wilcox.fun, .id = 'Group')
我想设置一个参数,以便函数对某些组计数,而不是连续计数。
我想得到什么
| Group|
|--------|
| 1 |
| 1 |
| 1 |
| 3 |
| 3 |
| 3 |
或另一个订单,例如:(2 和 3)
我的数据框:
data <- structure(list(group = c(1L, 1L, 1L, 1L, 1L, 1L,1L,1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), col1 = c(9,
9.05, 7.15, 7.21, 7.34, 8.12, 7.5, 7.84, 7.8, 7.52, 8.84, 6.98,
6.1, 6.89, 6.5, 7.5, 7.8, 5.5, 6.61, 7.65, 7.68,8.0,9.0), col2 = c(11L,
11L, 10L, 1L, 3L, 7L, 11L, 11L, 11L, 11L, 4L, 1L, 1L, 1L, 2L,
2L, 1L, 4L, 8L, 8L, 1L,3L,4L), col3 = c(7L, 11L, 3L, 7L, 11L, 2L, 11L,
5L, 11L, 11L, 5L, 11L, 11L, 2L, 9L, 9L, 3L, 8L, 11L, 11L, 2L,5L,6L),
col4 = c(11L, 11L, 11L, 11L, 6L, 11L, 11L, 11L, 10L, 7L,
11L, 2L, 11L, 3L, 11L, 11L, 6L, 11L, 1L, 11L, 11L,13L,12L), col5 = c(11L,
1L, 2L, 2L, 11L, 11L, 1L, 10L, 2L, 11L, 1L, 3L, 11L, 11L,
8L, 8L, 11L, 11L, 11L, 2L, 9L,4L,5L)), .Names = c("group", "col1",
"col2", "col3", "col4", "col5"), class = "data.frame", row.names = c(NA,
-21L))