[BioC] as.numeric and NA

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Tue May 31 11:44:55 CEST 2005


See comments below.

On Mon, 2005-05-30 at 13:08 +0200, Mohammad Esad-Djou wrote:
> Hello, 
> 
> I would like to use for 42 experiments "as.numeric" (objects of type '"numeric"')
> I wrote in such a way:
> 
> > library(affy)
> > data.raw <- ReadAffy(filenames= "./R/ME_cel/Expt1_R1.CEL",
> ...    "./R/ME_cel/Expt14_R3.CEL")

Can you try to use the following instead please

raw <- ReadAffy( filenames=c("Expt1_R1.CEL", "Expt14_R3.CEL"), 
                 celfile.path="./R/ME_cel/" )

I am aware that you do not need the "c" for ReadAffy() to work but it is
conventional with R when quote it as an array.

> > as.numeric(sampleNames(data.raw))
>  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> [26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> Warning message:
> NAs introduced by coercion

As the warning says and as demonstrated by Kasper, the NA's you get is
from coercion of string characters. 

> How can I find correctly numeric values of data.raw?

It would have helped if you shown the output of sampleNames(data.raw) or
what you mean by numeric values. 

Assuming you want to extract the value of "14" from Expt14_R3.CEL, try

cn <- c("Expt1_R1.CEL", "Expt14_R3.CEL") 
# replace this with cn  <- sampleNames(data.raw)

tmp <- strsplit( cn, split="_" )
tmp <- sapply( cn, function(x) unlist(strsplit(x, split="_"))[[1]] )
gsub("Expt", "", tmp)
[1] "1"  "14"
as.numeric( gsub("Expt", "", tmp) )
[1]  1 14


If I assume that you want to extract "3" from Expt14_R3.CEL, try instead

tmp <- strsplit( cn, split="_" )
tmp <- sapply( cn, function(x) unlist(strsplit(x, split="_"))[[2]] )
as.numeric( gsub( "R", "", gsub(".CEL", "", tmp) ) )


Next time, please learn to ask the question more clearly (with example
of the desired output) to avoid the rest of guessing (e.g. what do you
mean by "correctly finding numeric values").

> Thanks,
> Mohammad Esad-Djou
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
>



More information about the Bioconductor mailing list