如何获得 NA 值而不是“数据本质上是恒定的"R 中的 t.test 中的错误 [英] How to get NA values instead of a "data are essentially constant" error in t.test in R

查看:26
本文介绍了如何获得 NA 值而不是“数据本质上是恒定的"R 中的 t.test 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自两组的大型数据集.我想使用 t.test 比较它并获取所有以 F_ 开头的列的 p.values 列表,但由于某些列中的数据,当我使用我的代码时:

I have a large dataset of data from two groups. I want to compare it using a t.test and get a list of p.values for all the columns starting with F_, but because of the data in some columns, when I use my code:

TP_FN_ttest <- Map(t.test, x = TP[,grepl(paste0("^F_"),colnames(TP))], 
                           y = FN[,grepl(paste0("^F_"),colnames(FN))])
TP_FN_ttest.pval <- as.data.frame(sapply(TP_FN_ttest, '[[', 'p.value'))

我收到一个错误:

Error in t.test.default(x = dots[[1L]][[508L]], y = dots[[2L]][[508L]]) : 
data are essentially constant

有没有办法在无法应用测试而不是出现错误时获取 p.values 列表并获取 NA?

Is there a way to get a list of p.values and get NA's whenever the test cannot be applied instead of getting an error?

推荐答案

你可以像这样使用 try catch 块:

You can use a try catch block like this:

tryCatch({
  ttest()
}, error = {
  somethingElse()
})

这篇关于如何获得 NA 值而不是“数据本质上是恒定的"R 中的 t.test 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆