[R] Data.matrix fail to convert data.frame into matrix
    Gundala Viswanath 
    gundalav at gmail.com
       
    Thu Jun 12 05:28:33 CEST 2008
    
    
  
Hi,
With the following codes, I attempt to convert
the data.frame into a matrix.
However I notice that data.matrix function doesn't
seem to work.
__ BEGIN__
dat <- read.table("mydata", comment.char = "!" , na.strings = "null");
# Select n-genes by random sample
# n = 1
nosamp <- 1
geneid <- sequence(nrow(dat))
geneid.samp <- sample(geneid,nosamp)
geneid.samp
gexp<- dat[geneid.samp,]
gexp.arr <- data.matrix(gexp, rownames.force = NA)
print(is.matrix(gexp.arr))
print(gexp.arr)
__END__
Yielding this output:
__BEGIN__
>  print(is.matrix(gexp.arr))
[1] TRUE
>  print(gexp.arr)
            V1     V2    V3    V4    V5    V6    V7    V8
10354 803.1 1107.8 431.6 349.8 386.7 646.3 744.2 620.9
__END__
I expect "gexp.arr" to be a plain vector (numeric).
What's wrong with my code above?
-- 
Gundala Viswanath
Jakarta-Indonesia
    
    
More information about the R-help
mailing list