Change order of columns in table?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Change order of columns in table?

someone
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!
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

Thomas Stewart
7 data points?  What's wrong with with doing it manually?

x<-c(173,193,194,167,119,80,96)
labs<-c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
pie3D(x,labels=labs)

-tgs

On Mon, May 17, 2010 at 8:46 AM, someone <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

someone
well, actually the script is run by crone job once in a while and id hate to do things manually...
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

David Winsemius

On May 17, 2010, at 10:31 AM, someone wrote:

>
> well, actually the script is run by crone job once in a while and id  
> hate to
> do things manually...

The order of levels of  a factor variable variable can be changed with  
a call along the lines of
fac <- factor(fac, levels=c"(Monday", "Tuesday", ..... ) )

Whether that will be applicable to this problem is unclear since you  
have provided such skimpy detail. (And please do not break the email  
chain in the future.)
--
David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

Joshua Wiley-2
In reply to this post by someone
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

Gabor Grothendieck
In reply to this post by someone
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

Jim Lemon
In reply to this post by someone
On 05/17/2010 10:46 PM, someone 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...

Hi someone,
The old "default alphabetical order" gotcha, huh? Well, let's just turn
the table on that there sneaky varmint.

1) I reckon that the old woman (the crone) who sets up this table is
always gonna do it that way, 'cause ya cain't teach an old crone new tricks.

2) We'll make up a little vector of numbers that'll recombobulate the
table, and we won't tell the old crone.

recombobulate<-c(2,6,7,5,1,3,4)

3) Then we'll feed 'er right into pie3D just like this:

pie3D(weekly[recombobulate],labels=names(weekly)[recombobulate],
  main="Yer table recombobulated")

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Change order of columns in table?

someone
thanks jim...
that really was some usefel help!