t.test(antibioticdata$Bacteria,
antibioticdata$Inhibition,
alternative = c("two.sided"),
paired = FALSE,
var.equal = FALSE)
这是我的R代码,用于对一组有关细菌抗生素耐药性的数据进行t检验。这给了我错误代码:
Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In var(x) :
Calling var(x) on a factor x is deprecated and will become an error.
Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
不确定我做错了什么
答案 0 :(得分:1)
我刚刚遇到了同样的错误。这可能是由于每个组中的所有值都相同。
所以再写两个“ if else”。对我来说,我做了
library("greenbrown")
apply(data.table, 1, function(x){
if(AllEqual(x[1:9])){return(1)}
else if(AllEqual(x[1:4]) & AllEqual(x[5:9])){return(0)} else {
t.test(as.numeric(x[1:4]), as.numeric(x[5:9]))->t.results
return(t.results$p.value)
}
})->P.for.data.table