[R] Change order of columns in table?

Gabor Grothendieck ggrothendieck at gmail.com
Mon May 17 17:34:18 CEST 2010


Assuming you really do have a table,

> tab <- as.table(c(Friday=119, Monday=173, Saturday=80,
+ Sunday=96, Thursday=167, Tuesday=193, Wednesday=194))
> tab
   Friday    Monday  Saturday    Sunday  Thursday   Tuesday Wednesday
      119       173        80        96       167       193       194

we can  use the fact that May 17, 2010 is a Monday to write this:

> tab[format(as.Date("2010-05-17") + 0:6, "%A")]
   Monday   Tuesday Wednesday  Thursday    Friday  Saturday    Sunday
      173       193       194       167       119        80        96

This last line should also work if tab is a data frame rather than a table.


On Mon, May 17, 2010 at 8:46 AM, someone <vonhoffen at t-online.de> wrote:
>
> I'm an R noob and have a (maybe) stupid question...
> I have a table where I have the weekdays and a number for each weekday of
> entries:
> Thats what the table looks like...
> Now I want to have an pie3D plot of this, but obviously the order of the
> weekdays are not as one would expect...
>   Friday    Monday  Saturday    Sunday  Thursday   Tuesday Wednesday
>      119       173        80               96       167            193
> 194
>
> how can I rearrange the cols so that its the "usal" way: monday first, then
> tuesday and so on...
> Any help is highly appreciated!
> --
> View this message in context: http://r.789695.n4.nabble.com/Change-order-of-columns-in-table-tp2219536p2219536.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list