#### The support.bioconductor.org editor has been updated to markdown! Please see more info at: Tutorial: Updated Support Site Editor

Question: converting integer to numeric
0
3.2 years ago by
Angel40
Berlin
Angel40 wrote:

hi

i have a matrix but im facing this error

mycounts <- read.table("newMat.txt", header = T, sep = "\t")
IDs AT1G01060 AT1G01170 AT1G01180
1 AT1G01060         0         0         0
2 AT1G01170         0         0         0
3 AT1G01180         0         0         0
4 AT1G01183         0         0         0
5 AT1G01260         0         0         0
6 AT1G01380         0         0         0

list object cannot be coerced to type integer

how i can convert an integer to numeric please?

thank you

software error • 2.4k views
modified 3.1 years ago • written 3.2 years ago by Angel40
2
3.2 years ago by
Sweden
Nicolas Delhomme320 wrote:
2
3.2 years ago by
arfranco130
European Union
arfranco130 wrote:

Add that an integer is also a numeric value, just lacking decimals

You need to add as row.names the values contained in the first column, and then, erase the first column

You have code showing the way of do it

2
3.1 years ago by
Hervé Pagès ♦♦ 13k
United States
Hervé Pagès ♦♦ 13k wrote:
1. This is not a Bioconductor question. It's about basic manipulations in R. This kind of questions is better asked on the R-help mailing list (https://stat.ethz.ch/mailman/listinfo/r-help).
2. You're showing us code but you omitted the most important part which is the command that actually caused the error.
3. The question you ask ("how i can convert an integer to numeric") doesn't seem directly related to the code you show. To convert an integer vector to a numeric vector, just call as.numeric() on it. However, your mycounts object is a data.frame, not an integer vector.
4. It could be that you got the error message you show us by calling as.integer() on the mycounts data.frame. A data.frame is a special kind of list hence the error message you got. Note that calling as.integer() on a list only works in the very particular case where all the list elements have a length <= 1.
5. Calling as.matrix() on your mycounts data.frame should work except that it will turn it into a character matrix, not an integer matrix. As Nico said, that's because one of the columns (the 1st one) in your data.frame is of type character (or factor). To get an integer matrix, you first need to get rid of this column. You can do this either by subsetting mycounts with as.matrix(mycounts[ , -1]), or by tweaking your call to read.table() as showed by Nico.

Cheers,

H.

0
3.1 years ago by
Angel40
Berlin
Angel40 wrote:

thank you all