我有一个excel文件,有25列和300行,每个列都有相同的行数。我需要对每一列做科查兰的测试,而不是其他每一列。
library(readxl)
library(outliers)
sheet2=read_excel("C:/Users/Sharas/Desktop/data.xlsx", sheet = 2)
for(i in 1:length(sheet2)) {
for(j in i:length(sheet2)) {
cochran.test(sheet2[[i]]~sheet2[[j]], sheet2)
}
}我一直在犯这个错误:
Error in split.default(X, group) : first argument must be a vector返回类型:双倍
print(typeof(sheet2[[i]]) 发布于 2016-05-22 21:50:56
这可能会让你更接近:
# Make data.frame with possible combinations of columns.
d <- sheet2
names <- colnames(d)
name.combinations <- subset(merge(names, names), x != y)
# Run test for each combination, build formula from string.
res <- mapply(function(x, y) {
cochran.test(as.formula(paste(x, " ~ ", y, sep = "")), d)
}, name.combinations$x, name.combinations$y)https://stackoverflow.com/questions/37379660
复制相似问题