[R] format: from list to data frame

Marc Schwartz marc_schwartz at me.com
Sat Mar 13 17:59:11 CET 2010


On Mar 13, 2010, at 10:46 AM, Javier wrote:

> 
> Dear users,
> 
> Is anyone out there on a Saturday to answer this easy question?
> 
> I have the "yo" object data in a "list" format:


It is not a list, it is a matrix.  The dimnames attribute is a list.


>> str(yo)
> num [1:259, 1:173] 16.3 NA NA NA NA ...
> - attr(*, "dimnames")=List of 2
>  ..$ x: chr [1:259] "367319" "367329" "367309" "367339" ...
>  ..$ y: chr [1:173] "780175" "780185" "780195" "780205" ...
>> length(yo)
> [1] 44807
> 
> where x is the name of the rows and y the name of the columns (coordinates)
> of a matrix of 44807 values
> 
> how can I get a data.frame with these three columns: x, y, values
> 
> Many thanks to the Saturday working people.
> 
> Javier					

Try:

 as.data.frame.table(yo)

HTH,

Marc Schwartz



More information about the R-help mailing list