Re: [R] transform a table into a matrix

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue, 24 Jun 2008 18:36:19 +0200

>>>>> "JohnF" == John Fox <jfox_at_mcmaster.ca> >>>>> on Tue, 24 Jun 2008 08:10:43 -0400 writes:

    JohnF> Dear Maria, On 23-Jun-08, at 11:40 PM, Maria     JohnF> Gavilanez wrote:

>> Hi.
>>
>> is there a way to transform a table that has numeric and
>> categorical variables into a matrix?

    JohnF> No, because all of the elements of a matrix must be
    JohnF> of the same mode, but a dataframe is a data structure
    JohnF> that can have heterogeneous columns. It's unclear
    JohnF> from your question where the "table" is located -- in
    JohnF> a file perhaps? If so, you can use read.table() to
    JohnF> read the data into a dataframe.

Yes, and then possibly use data.matrix(.) to produce a numeric matrix where the "categorical variables" have become numeric (via their internal codes).

Martin Maechler, ETH Zurich

    JohnF> I hope this helps, John

    JohnF> -------------------------------------------- John
    JohnF> Fox, Professor Department of Sociology McMaster
    JohnF> University Hamilton ON Canada L8S 4M4 web:     JohnF> socserv.mcmaster.ca/jfox

>>
>>
>> thanks
>>
>>
>> Maria Mercedes Gavilanez Department of Biological
>> Sciences 107 Life Sciences Building Louisiana State
>> University Baton Rouge, LA 70803 (225)578-4284
>>
>> ______________________________________________
>> 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.

    JohnF> ______________________________________________
    JohnF> R-help_at_r-project.org mailing list
    JohnF> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE
    JohnF> do read the posting guide
    JohnF> http://www.R-project.org/posting-guide.html and
    JohnF> provide commented, minimal, self-contained,     JohnF> 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 Tue 24 Jun 2008 - 16:41:59 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 Tue 24 Jun 2008 - 17:31:01 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