convert a character vector into a numeric vector
1
0
Entering edit mode
@libyatahani-9206
Last seen 7.6 years ago
Libyan Arab Jamahiriya

hi,

My code for my analysis is as the following then my ask is in the end :

> dat
AffyBatch object
size of arrays=640x640 features (19 kb)
cdf=HG_U95Av2 (12625 affyids)
number of samples=8
number of genes=12625
annotation=hgu95av2
notes=

> dat2<-rma(dat)

> dat.m<-exprs(dat2)

> rsd<-rowSds(dat.m)

> i<-rsd>=2
> dat.f<-dat.m[i,]

> ff<-pOverA(A=1, p=0.5)
> i<-genefilter(dat.m, ff)
> dat.fo<-dat.m[i,]

> ff<-pOverA(A=1, p=0.5)
> i<-genefilter(-dat.m, ff)
> dat.fu<-dat.m[i,]

dat.f<-rbinddat.fo, dat.fu)

> design
  absent10 absent48 present10 present48
1        1        0         0         0
2        1        0         0         0
3        0        0         1         0
4        0        0         1         0
5        0        1         0         0
6        0        1         0         0
7        0        0         0         1
8        0        0         0         1
attr(,"assign")
[1] 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$f
[1] "contr.treatment"

> fit<-lmFit(dat.f, design)
> fit<-eBayes(fit)
> toptable(fit, coef=2)
                   logFC        t      P.Value    adj.P.Val        B
AFFX-hum_alu_at 14.74942 192.5894 9.712584e-17 8.264148e-14 24.92559
31962_at        14.68759 192.0779 9.934044e-17 8.264148e-14 24.91928
35905_s_at      14.67268 191.2009 1.032704e-16 8.264148e-14 24.90838
33824_at        14.68408 190.7521 1.053488e-16 8.264148e-14 24.90275
31957_r_at      14.65359 190.7216 1.054917e-16 8.264148e-14 24.90237
34593_g_at      14.59091 189.6964 1.104239e-16 8.264148e-14 24.88938
32744_at        14.53773 189.4014 1.118907e-16 8.264148e-14 24.88561
40887_g_at      14.60499 189.0208 1.138153e-16 8.264148e-14 24.88072
2016_s_at       14.44201 188.6353 1.158025e-16 8.264148e-14 24.87575
31527_at        14.43456 188.5953 1.160108e-16 8.264148e-14 24.87523

 

> rn<-rownames(toptable(fit, coef=2, n=100))

> tt<-toptable(fit, coef=2, n=nrow(dat.m))

> rn<-rownames(tt)[tt$P.Value<=0.001]

Those names are actually stored in a character vector, but I
need to convert it into a numeric vector:

> rn<-as.numeric(rn)
Warning message:
NAs introduced by coercion 

Also I tried the following :

> which.min(rn)
integer(0)

any help to get rn<-as.numeric(rn) please ?? Because I need it for extract the genes from the original data by the next command:

dat.s<-dat.m[rn,] 

which will stores the data for the genes that were selected (as
differentially expressed).

cheers,

Tahani.

 

 

differential gene expression • 1.1k views
ADD COMMENT
1
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 19 hours ago
The city by the bay

The row names are not the same as the row indices. Trying to convert row names to numeric values doesn't make any sense in most scenarios - even when the row names are numbers, there's no guarantee that the first row is named "1". For example, what number do you expect "31962_at" to be converted to, and how would this number be relevant to the row index for that probe? Rather, you need to do something like:

rdex <- match(rn, rownames(dat.m))

Then you can subset dat.m based on rdex, which will give you the rows with names equal to rn. Also, you should really be using topTable, not toptable. The latter is only maintained for backwards compatibility.

ADD COMMENT
1
Entering edit mode

Why use an explicit match, instead of just the character subscript? You can subscript rectangular objects by rownames on the first dimension.

ADD REPLY
0
Entering edit mode

Ah... that's probably the simpler way. I've been using match in my code, mostly so that I can handle cases where the requested row name doesn't exist by intercepting the resulting NA values. But that seems to be unnecessary here.

ADD REPLY
0
Entering edit mode

Thanks a lot Aaron Lun ..

ADD REPLY

Login before adding your answer.

Traffic: 568 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6