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

From: Moshe Olshansky <m_olshansky_at_yahoo.com>
Date: Wed, 11 Jun 2008 21:37:12 -0700 (PDT)


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).

> 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.



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. Received on Thu 12 Jun 2008 - 05:05:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Jun 2008 - 06:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive