stephen sefick
2008-Apr-15 22:35 UTC
[R] Transposing Data Frame does not return numeric entries
x <- read.table("LittleGarvin.csv", sep=",", header=TRUE) y <- t(x) str(y) chr [1:193, 1:288] "oligocha" "0" " 0" " 0" " 0" "0" ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:193] "X" "upwd1201" "upwd0502" "upwd0702" ... ..$ : NULL x is a data frame with a whole bunch of numeric vectors I would like for the rows and columns to be reversed == transposed but with the same attributes. I am trying to feed the transposed data frame to metaMDS(vegan). I am stumped- sorry for the large attached file- I am at a loss. Stephen Sefick -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
stephen sefick
2008-Apr-15 22:57 UTC
[R] Transposing Data Frame does not return numeric entries
I have a species as rows and sites as columns matrix. I would like to tranpose this matrix so that I can do an NMDS analysis with the vegan package. I have used y <- t(x) and it indeed transposes the matrix, but it changes the whole make up chr [1:193, 1:288] "oligocha" "0" " 0" " 0" " 0" "0" ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:193] "X" "upwd1201" "upwd0502" "upwd0702" ... ..$ : NULL the original matrix is numeric when I use str(x). I would post the data but it is large for a mailing list. I have read help and I can't figure it out. -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]]
Rolf Turner
2008-Apr-15 23:08 UTC
[R] Transposing Data Frame does not return numeric entries
RML: *** Data frames are NOT matrices!!! *** On 16/04/2008, at 10:35 AM, stephen sefick wrote:> x <- read.table("LittleGarvin.csv", sep=",", header=TRUE) > y <- t(x) > str(y) > > chr [1:193, 1:288] "oligocha" "0" " 0" " 0" " 0" "0" ... > - attr(*, "dimnames")=List of 2 > ..$ : chr [1:193] "X" "upwd1201" "upwd0502" "upwd0702" ... > ..$ : NULL > > x is a data frame with a whole bunch of numeric vectors I would > like for the > rows and columns to be reversed == transposed but with the same > attributes. > I am trying to feed the transposed data frame to metaMDS(vegan). I am > stumped- sorry for the large attached file- I am at a loss.Although it is possible, transposition makes little to no sense for data frames. If you want to transpose something you are thinking of it as being a *matrix* not a data frame. The result of transposing a data frame is in fact a matrix. There is as far as I know no structure in R whereby the rows of a matrix-like object can have different characteristics. (The term ``attributes'' has a technical meaning in R which is probably not what you intend --- but even if you do intend that, it's not possible.) The complaint made in your subject line is that the result of your transposition is not numeric. It is in fact character. That's because there is character data in the data frame x. When you transpose x, it is first coerced into a matrix. If there are any character or factor columns in x the coercion will result in a character matrix, the transpose of which will of course be a character matrix. The solution is of course to remove the character or factor columns from x before transposition. If you ``can't'' do this, then you ***can't*** transpose --- transposition just doesn't make any sense at all. Simple as that. cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Maybe Matching Threads
- Splitting row names up and then adding up the columns associated with criteria from the parts of the site coding (help)
- transpose of complex matrices in R
- Matrix transposition
- Programcode and data in the same textfile
- Unusual slowing of R matrix multiplication version 2.12.1 (2010-10-15) vs 2.12.0