[R] Data.matrix fail to convert data.frame into matrix

Moshe Olshansky m_olshansky at yahoo.com
Thu Jun 12 06:37:12 CEST 2008


Try
gexp.arr <- data.matrix(gexp, rownames.force = FALSE)

You are still supposed to get a matrix with one row (not a vector - dim(gexp.arr) is c(1,8) and not NULL).


--- On Thu, 12/6/08, Gundala Viswanath <gundalav at gmail.com> wrote:

> From: Gundala Viswanath <gundalav at gmail.com>
> Subject: [R] Data.matrix fail to convert data.frame into matrix
> To: r-help at stat.math.ethz.ch
> Received: Thursday, 12 June, 2008, 1:28 PM
> 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.



More information about the R-help mailing list