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.
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 <vonhoffen@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@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. >[[alternative HTML version deleted]]
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.
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
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))> tabFriday 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. >
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
thanks jim... that really was some usefel help! -- View this message in context: http://r.789695.n4.nabble.com/Change-order-of-columns-in-table-tp2219536p2222806.html Sent from the R help mailing list archive at Nabble.com.