Thanks Pete.  That is exactly what I was missing.

On Sat, Mar 2, 2013 at 5:43 PM, Pete Brecknock [via R] <
ml-node+s789695n4660129h86@n4.nabble.com> wrote:

>  cdouglass wrote
> Hello all,
>
> Totally new to this and I'm just doing a frequency distribution analysis
> on T-shirt sales by size.  I have a .csv with 60 orders.  I read in the
> data using read.csv.  If I look at the summary() or table() of the data it
> looks fine, except that the shirt sizes are alphabetical rather than from
> S-XXL--so the bar graph loses the shape of the data based on size.
>
> All I want to do is get the table to arrange the data:
> S M L XL XXL
>
> Here's the code that I've run that got me closer to what I want.  It seems
> like it should be simple, but going through the "R in a Nutshell" and
> asking Google as many different ways as I can think to phrase it are
> turning up nothing.
>
> > shirt <- read.csv("http://localhost/examples/tshirt_purchases.csv",
> header=TRUE, sep = ",", nrows=60)
> > shirt.table<-summary(shirt)
> > shirt.table
>  Shirt.Size
>  L  :20
>  M  :20
>  S  :11
>  XL : 7
>  XXL: 2
>
> What I want is:
>
> Shirt.Size
> S  :11
> M  :20
> L  :20
>  XL : 7
>  XXL: 2
>
> Does anyone know how to do this, or am I coming at it from the wrong
> direction?
> If this has been answered previously and I've just failed to find it in my
> searches, please accept my apologies.
>
> Many Thanks,
> Chris
>
> Think you want to have a look at factors....
>
> Typing ?factor will throw up the relevant help pages
>
> # Your Data
> tbl <- read.table(header = TRUE, text = "
>  ShirtSize Number
>  L 20
>  M 20
>  S 11
>  XL 7
>  XXL 2
> ")
>
> # ShirtSize Alphabetical
> tbl[tbl$ShirtSize,]
>
> # Reorder Factor
> tbl$ShirtSize = factor(tbl$ShirtSize, levels=c("S","M","L","XL","XXL"))
>
> # ShirtSize Order by Size
> tbl[tbl$ShirtSize,]
>
>
> Pete
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
> http://r.789695.n4.nabble.com/Ordering-Table-Columns-tp4660110p4660129.html
>  To unsubscribe from Ordering Table Columns, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4660110&code=Y2hyaXN0b3BoZXJzY290dGRvdWdsYXNzQGdtYWlsLmNvbXw0NjYwMTEwfC0xNDgwNzI5MzU5>
> .
> NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




-----
- Cloning is the sincerest form of flattery.
--
View this message in context: http://r.789695.n4.nabble.com/Ordering-Table-Columns-tp4660110p4660296.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

