Kruskal.test.default(e,f)中的Kruskal测试错误:';x';和';g';必须有相同的长度

Kruskal.test.default(e,f)中的Kruskal测试错误:';x';和';g';必须有相同的长度,r,kruskal-wallis,R,Kruskal Wallis,我正在尝试对以下数据集进行kruskal-wallis测试: e<-c(0.0018, 0.0021, 0.0028, 0.0029, 0.0044, 0.0045, 0.0074, 0.00325140981291511,0.00325140981291511, 0.00325140981291511, 0.0079, 0.001978252063446,0.00684016798870973, 0.00384959728634123, 0.0093, 0.011, 0.014, 0.0

我正在尝试对以下数据集进行kruskal-wallis测试:

e<-c(0.0018, 0.0021, 0.0028, 0.0029, 0.0044, 0.0045, 0.0074, 0.00325140981291511,0.00325140981291511, 0.00325140981291511, 0.0079, 0.001978252063446,0.00684016798870973, 0.00384959728634123, 0.0093, 0.011, 0.014, 0.022, 0.083, 0.48, 0.49, 1.2)

f<-c(0.0145458371613749, 0.0355067948032862, 0.0654819408270916, 0.107370481645772, 0.165362828209794, 0.0654819408270916, 0.253, 0.344, 0.42, 1.3, 2.7, 3.14, 3.93, 4.48, 5.48, 17)

?kruskal.test
中所述,您的第二个参数必须是指示组的因子。因此:

# Combine the data in a single vector
x <- c(e,f)
# create a group indicator
groups <- rep(c(1,2), 
              times = c(length(e), length(f))
              )
# profit
kruskal.test(x, groups)

#   Kruskal-Wallis rank sum test
# 
# data:  x and groups
# Kruskal-Wallis chi-squared = 18.136, df = 1, p-value = 2.057e-05
#将数据合并到一个向量中

我相信它需要x中的一个数值向量和g中的一个因子,其中g的每个元素描述x的对应值属于哪个组。这就是为什么它要你输入长度相等的向量。@svenhalvorson你的信念是正确的;-)谢谢我很感激
# Combine the data in a single vector
x <- c(e,f)
# create a group indicator
groups <- rep(c(1,2), 
              times = c(length(e), length(f))
              )
# profit
kruskal.test(x, groups)

#   Kruskal-Wallis rank sum test
# 
# data:  x and groups
# Kruskal-Wallis chi-squared = 18.136, df = 1, p-value = 2.057e-05