Re: [R] Way to convert data frame to matrix

From: Charles C. Berry <>
Date: Sun 02 Jul 2006 - 01:47:13 EST

I think this will do what you want:

dframe <- read.table("your.text.file", <other args as needed> )

mat <- tapply(dframe[,3],dframe[,1:2],c)

On Fri, 30 Jun 2006, Wade Wall wrote:

> I have a text file that I have imported into R. It contains 3 columns and
> 316940 rows. The first column is vegetation plot ID, the second species
> names and the third is a cover value (numeric). I imported using the
> read.table function.
> My problem is this. I need to reformat the information as a matrix, with
> the first column becoming the row labels and the second the column labels
> and the cover values as the matrix cell data. However, since the
> read.tablefunction imported the data as an indexed data frame, I can't
> use the columns
> as vectors. Is there a way around this, to convert the data frame as 3
> separate vectors? I have been looking all over for a function, and my
> programming skills are not great.
> Thanks in advance
> [[alternative HTML version deleted]]
> [ Part 3.23: "Included Message" ]

Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E	         UC San Diego         La Jolla, San Diego 92093-0717

______________________________________________ mailing list PLEASE do read the posting guide! Received on Sun Jul 02 01:51:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 02 Jul 2006 - 02:13:20 EST.

Mailing list information is available at Please read the posting guide before posting to the list.