Re: [R] Transposing Data Frame does not return numeric entries

From: stephen sefick <ssefick_at_gmail.com>
Date: Tue, 15 Apr 2008 20:40:15 -0400

ok

                site1   site2  site3  site4
species1     1         2       3       4
species2      3        0       4       5
species3     5          3      7        3
spesies4     0         3       6        7

             species1   species2  species3  species4
site1           1               3            5              0
site2           2               0            3              3
site3           3               4            7              6
site4           4               5            3              7

this is what I want to do. It is hard to learn R as I have never programed anything in my life, but I am learning slowly. I am a researcher who finds statistics indispensable. I apologize for my flawed logic but this is what I want to do.

x <- read.table("file.csv", sep=",", header=T) it is is correct I just want to flip the rows and columns. How do I do this? sorry for my lack of understanding. All help is greatly appreciated.

Stephen

On Tue, Apr 15, 2008 at 7:08 PM, Rolf Turner <r.turner_at_auckland.ac.nz> wrote:

>
> 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 confidential. If you are
> not theintended recipient please delete the message and notify the
> sender.Any views or opinions presented are solely those of the author.
>
> This e-mail has been scanned and cleared by MailMarshal
> www.marshalsoftware.com
> ######################################################################
>

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 16 Apr 2008 - 00:42:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Apr 2008 - 02:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive