0

I tend to apply t-test for each row in my data frame, which is the microarray data, comparing columns 2:13 and 14:67 by these code:

t_test = apply(Df, 1, function(x) { t.test(x[2:13], x[14:67])$p.value } )

However, I got this error:

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 mean.default(y) :

I have checked if any value is missing/non-numeric or not by some advice about these issues (it seems like many people got this issue as well) by this code:

TRUE %in% is.character(Data_rma[2:13])  TRUE %in% is.character(Data_rma[14:67])
TRUE %in% is.na(Data_rma[2:13])  TRUE %in% is.na(Data_rma[14:67])

Nothing is missing and all the values are numeric. I don't know what's the problem with my issue.

Thank you very much!

I have uploaded my Data frame to Drive so you can try it. https://drive.google.com/file/d/1FE81HYaSTo7rEPG-qb-mdknPcpvebsWT/view?usp=sharing

My Data Frame likes this

UseR10085
  • 7,120
  • 3
  • 24
  • 54

1 Answers1

0

This is an error that comes from the fact that when you apply by rows, you will be getting vectors with 3 columns of class "character" and therefore coercing all numeric to character. Then, the t-test is run on character variables and will fail.

The right way is to first determine which are the numeric columns and apply the test to a subset of the original data.

num_cols <- which(sapply(Data_rma, is.numeric))
i1 <- which(num_cols %in% 2:13)
i2 <- which(num_cols %in% 14:67)

t_test <- apply(Data_rma[num_cols], 1, function(x) {
  tryCatch(t.test(x[i1], x[i2])$p.value,
           error = function(e) e
  )
})

ok <- !sapply(t_test, inherits, "error")
all(ok)
#[1] TRUE

Data reading code

google_id <- "1FE81HYaSTo7rEPG-qb-mdknPcpvebsWT"
google_file <- sprintf("https://docs.google.com/uc?id=%s&export=download", google_id)
Data_rma <- read.csv(google_file)
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66