That won't always work. The data needs to be numeric and data.matrix is not strict enough to satisfy that. In all probability, your datExpr is a data.frame that has factors or logical columns which data.matrix converts to numeric type, but does not really have a non-convertible column. zx8754's answer that points OP to ensure all data is numeric is the right way to go.
See sample code that shows why data.matrix won't work:
x <- c("A","B","C")
x_fac <- factor(x, levels = c("B","A","C"), ordered = TRUE)
################
df_fac <- data.frame(col1=c(1,2,3), col2=x_fac, col3=c(TRUE,FALSE,TRUE), stringsAsFactors = FALSE) #col2 is a factor here
df_fac
col1 col2 col3
1 1 A TRUE
2 2 B FALSE
3 3 C TRUE
data.matrix(df_fac)
col1 col2 col3
[1,] 1 NA 1
[2,] 2 NA 0
[3,] 3 NA 1
Warning message:
In data.matrix(data.frame(col1 = c(1, 2, 3), col2 = x, col3 = c(TRUE, :
NAs introduced by coercion
################
df_nonfac <- data.frame(col1 = c(1,2,3), col2 = x, col3 = c(TRUE,FALSE,TRUE), stringsAsFactors = FALSE) #col2 is not a factor here
col1 col2 col3
1 1 A TRUE
2 2 B FALSE
3 3 C TRUE
data.matrix(df_nonfac)
col1 col2 col3
[1,] 1 2 1
[2,] 2 1 0
[3,] 3 3 1
See how it works perfectly when columns are numeric, logical or factor but not otherwise? The trick is to handle non-numeric columns, not use a data.matrix blindly.
Error is clear: "datExpr must contain numeric data"
Hello,
Did you solve it?
I have the same problem, goodSampleGenes does not read the numbers, but when continuing to the sample clustering it returns results!
I do not really know the mistake I am doing. I checked with srt() function and there is numeric data.
My commands are:
Thanks for your help.
This should be a comment on the post, not an "answer", as you're not really answering sh.o.94's question. I'm moving it to a comment now, but please be more careful in the future.
By the way, did you look at zx8754's pointer? It should help you get to the solution.