[R] Change order of columns in table?

Joshua Wiley jwiley.psych at gmail.com
Mon May 17 17:13:26 CEST 2010


Hello,

What about something like this?

week.table <- data.frame(Friday=119, Monday=173, Saturday=80,
Sunday=96, Thursday=167, Tuesday=193, Wednesday=194)
ordered <- c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
week.table <- week.table[,ordered]
library(plotrix)
pie3D(as.numeric(week.table[1,]),labels=names(week.table))

assuming your table always has columns named after days of the week,
you should be able to use the vector 'ordered' in a script to sort
your table as you want.  The labels in your 3d pie chart are created
using the names of from the dataframe.

Best regards,

Josh

On Mon, May 17, 2010 at 7:31 AM, someone <vonhoffen at t-online.de> wrote:
>
> well, actually the script is run by crone job once in a while and id hate to
> do things manually...
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Change-order-of-columns-in-table-tp2219536p2219725.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.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/



More information about the R-help mailing list