必须有一种R-ly方式wilcox.test使用group_by并行调用多个观察.我已经花了很多时间阅读这篇文章,但仍然无法弄清楚是否wilcox.test有这样的工作.下面的示例数据和代码,使用magrittr管道和summarize().
library(dplyr)
library(magrittr)
# create a data frame where x is the dependent variable, id1 is a category variable (here with five levels), and id2 is a binary category variable used for the two-sample wilcoxon test
df <- data.frame(x=abs(rnorm(50)),id1=rep(1:5,10), id2=rep(1:2,25))
# make sure piping and grouping are called correctly, with "sum" function as a well-behaving example function
df %>% group_by(id1) %>% summarise(s=sum(x))
df %>% group_by(id1,id2) %>% summarise(s=sum(x))
# make sure wilcox.test is …Run Code Online (Sandbox Code Playgroud)