r - t 检验的“数据基本不变”错误
问题描述
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.
不知道我做错了什么
解决方案
我刚刚遇到了同样的错误。这可能是由于每组中的所有值都相同。
所以只需再写两个“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
推荐阅读
- mongodb - MongoDB:设置和获取子文档模式
- ionic4 - Ionic 4如何在点击时更改段
- javascript - 错误说 queryResult 未定义,即使 queryResult 包含数据
- javascript - 如何防止使用plupload上传时自动重定向?
- c++ - c++ 运算符重载 - 我实际返回的是什么操作数类型?
- python - 如何在剪刀石头布程序中添加赢/输计数器
- oracle - 为预订服务报告调试 PL/SQL 过程
- zsh - Zshell 完成调用另一个函数
- c - C在没有#include的情况下告诉头文件关于ac文件中的结构
- ios - 如何安排和重复本地通知