Re: [R] Converting matrix to data frame without losing an assigned dimname

2013-04-10 Thread Paul Miller
Hi David, Gabor, Arun, and Rolf,   Thanks for your replies to my question. Very interesting and very helpful. I particularly liked the one-line solutions proposed by David and Gabor. I had a suspicion that this conversion could be done using only a minimal amount of code.   For what I'm doing, i

Re: [R] Converting matrix to data frame without losing an assigned dimname

2013-04-10 Thread David L Carlson
t; -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of arun > Sent: Tuesday, April 09, 2013 6:01 PM > To: Paul Miller > Cc: R help > Subject: Re: [R] Converting matrix to data frame without losing an > assign

Re: [R] Converting matrix to data frame without losing an assigned dimname

2013-04-09 Thread arun
3100  4862 #3 Pennsylvania   126  11860 44966 #2 Maryland   101   4122  9891 #4 Virginia    85   4981 39780 A.K. - Original Message - From: Paul Miller To: r-help@r-project.org Cc: Sent: Tuesday, April 9, 2013 4:52 PM Subject: [R] Converting matrix to data fram

Re: [R] Converting matrix to data frame without losing an assigned dimname

2013-04-09 Thread Rolf Turner
Interesting. The problem is that only ***arrays*** are allowed to have a dimnames attribute, and data frames are not arrays (they are lists). The only way that I can see to achieve the effect that you want is to make the row names into the first column of your data frame and wipe out the row na

Re: [R] Converting matrix to data frame without losing an assigned dimname

2013-04-09 Thread Gabor Grothendieck
On Tue, Apr 9, 2013 at 4:52 PM, Paul Miller wrote: > Hello All, > > Would like to be able to convert a matrix to a dataframe without losing an > assigned dimname. > > Here is an example that should illustrate what I'm talking about. > > tableData <- state.x77[c(7, 38, 20, 46), c(7, 1, 8)] > names

[R] Converting matrix to data frame without losing an assigned dimname

2013-04-09 Thread Paul Miller
Hello All, Would like to be able to convert a matrix to a dataframe without losing an assigned dimname. Here is an example that should illustrate what I'm talking about. tableData <- state.x77[c(7, 38, 20, 46), c(7, 1, 8)] names(dimnames(tableData)) <- c("State", "") tableData State F