问题
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'))
I get an error:
Error in t.test.default(x = dots[[1L]][[508L]], y = dots[[2L]][[508L]]) :
data are essentially constant
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?
回答1:
You can use a try catch block like this:
tryCatch({
ttest()
}, error = {
somethingElse()
})
来源:https://stackoverflow.com/questions/45186571/how-to-get-na-values-instead-of-a-data-are-essentially-constant-error-in-t-tes