Question: how I can keep row name for my matrix?
0
gravatar for F
6 weeks ago by
F2.5k
F2.5k wrote:

Hi,

I have a gene expression profile; genes in rows and samples in columns, but that was not numeric, when I tried as.numerric(as.character(x))

thelling : NAs introduced by coercion

when I tried

`as.matrix(as.data.frame(lapply(x, as.numeric)))`

my file become numeric but gene names were removed from rows like below

     probe cancer1 cancer2  cancer3

[1,]    27    8466 1.59275  0.35975

[2,]    28    9452 0.84700  0.15200

[3,]    29    8031 0.35325 -0.54750

[4,]    30    1735 0.24700 -0.93950

[5,]    31    9368 0.41800  0.10550

[6,]    32    3710 0.04650 -1.01075

how I can return or keep gene names in rows?

thank you

sequencing R software error • 139 views
ADD COMMENTlink modified 6 weeks ago • written 6 weeks ago by F2.5k
2
gravatar for zjhzwang
6 weeks ago by
zjhzwang150
zjhzwang150 wrote:

I think if you read file into R with row.names = 1 can avoid that problem, you will get a data frame just contain expression values and gene names as rownames.

ADD COMMENTlink written 6 weeks ago by zjhzwang150

thank you, but when I read my file like so

x<- read.table("mRNA.txt", header = T, sep = "\t",row.names = 1)

then

as.matrix(as.data.frame(lapply(x, as.numeric)))

only telling

x num [1, 1] 1
ADD REPLYlink modified 6 weeks ago by genomax226k • written 6 weeks ago by F2.5k
1

If only the first column is character, the x in your code just return a data frame, and all the values are numeric, so you don' t need to as.numeric.

ADD REPLYlink written 5 weeks ago by zjhzwang150

thank you

it worked

x=as.matrix(as.data.frame(x))
ADD REPLYlink modified 5 weeks ago by Ram11k • written 5 weeks ago by F2.5k
Please log in to add an answer.

Help
Access

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