[R] Transposing Data Frame does not return numeric entries

Rolf Turner r.turner at auckland.ac.nz
Wed Apr 16 01:08:07 CEST 2008


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}}



More information about the R-help mailing list