Question: error while making a DegList object on R using edgeR package (Error in colSums(counts) : 'x' must be numeric)
gravatar for deeksha3696
11 months ago by
deeksha369610 wrote:

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)
dgeFull <- DGEList(rawCountTable, group=sampleInfo$condition)

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

rna-seq R • 1.2k views
ADD COMMENTlink modified 9 months ago by Gordon Smyth1.3k • written 11 months ago by deeksha369610
gravatar for Gordon Smyth
9 months ago by
Gordon Smyth1.3k
Gordon Smyth1.3k wrote:

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.

ADD COMMENTlink modified 9 months ago • written 9 months ago by Gordon Smyth1.3k

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

           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!

ADD REPLYlink modified 8 months ago • written 8 months ago by jingjin220340

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

class(rawCountTable) <- "numeric"


ADD REPLYlink modified 8 months ago • written 8 months ago by jingjin220340
gravatar for h.mon
11 months ago by
h.mon29k wrote:

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.

ADD COMMENTlink written 11 months ago by h.mon29k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1123 users visited in the last hour