This is a test version of Biostars. For the public version, visit https://www.biostars.org.
error while making a DegList object on R using edgeR package (Error in colSums(counts) : 'x' must be numeric)

hey, I am doing an RNAseq analysis (using edgeR) I am loading my data for differential analysis, my data is of read counts. I am now just trying to make DEGList object but, it is showing "Error in colSums(counts): 'x' must be numeric. Please suggest what should I do. thank you!! command used:

rawCountTable <- read.table(file.choose(),header=TRUE)
sampleInfo <- read.table(file.choose(), header=TRUE)
library(edgeR)
dgeFull <- DGEList(rawCountTable, group=sampleInfo$condition)

Error in colSums(counts) : 'x' must be numeric

rna-seq r

2 answers

This is frequently asked question that arises because many R users don't appreciate the difference between a matrix and a data.frame in R.

I assume that you have a tab-delimited file of read counts. The first field of your file probably contains the Gene Ids and the other columns probably contain read counts. When you read the rawCountTable using read.table you get a data.frame where the first column is a factor with the Gene Ids as levels and the other columns contain integers.

However DGEList is expecting to get a matrix rather than a data.frame. DGEList tries to convert the data.frame to a matrix but finds that the first column of rowCountTable is not numeric and hence issues an error message.

Assuming that your file counts only one column of Gene Ids, then you can fix the problem by

rawCountTable <- read.delim(file.choose(), row.names=1)

This will ensure that the Gene Ids are stored as row.names instead of as a column.

Hi Gordon, I had the same problem and I tried to fix it following your post here. However, edgeR still gave the error message. Here is the code I used

rawCountTable <- read.delim("featureCount_counts", header = FALSE, sep = "\t", row.names = 1)

rawCountTable <- rawCountTable[-c(1,2), -c(1,2,3,4,5)] 

rawCountTable <- as.matrix(rawCountTable)

And after running head(rawCountTable), this is what I got

head(rawCountTable)
           V7    V8    V9    V10   V11  V12  V13   V14   V15   V16   V17  V18
TG_00001 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00002 "0"   "0"   "7"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_20621 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00003 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00004 "0"   "0"   "0"   "0"   "0"  "0"  "0"   "0"   "0"   "0"   "0"  "0"
TG_00005 "490" "221" "111" "138" "84" "34" "258" "128" "189" "146" "80" "2"

I am struggling with R and edgeR, I'd really appreciate it if you could take a look at this and help me out. Thanks a lot!

I realized the numbers in my matrix were characters. It looks like I have fixed it by

class(rawCountTable) <- "numeric"

Thanks!!

Please show the result of:

head( rawCountTable )

rawCountTable is probably a data frame with a non-numeric column corresponding to gene names. You want to make this column into the row names of rawCountTable, then remove this column, to keep only numeric values.

Log in to answer this question.