Re: [R] convert decimals to fractions - sorted

From: JeeBee <>
Date: Fri 28 Jul 2006 - 21:42:22 EST

Ah I see, I did not read your story well enough. You want to sort after applying table()
Well, the idea I suggested was to keep the real numbers in, because the fractions are sorted as characters strings (alphabetically), which is not what you want. So, now I suggest the following:

# First apply table()

tmp1 <-

# Note that table() turned your numeric data into factors,
# this might not be a handy approach, anyways, it is possible I guess.
# You have to convert back using as.numeric(as.character(tmp1$V2))
# or, more efficiently, as.numeric(levels(tmp1$V2))[tmp1$V2]

# Add the column with the fractions

tmp2 <- cbind(tmp1,


# Finally hide that sort colum if you want

( tmp2[-2] )

# Everybody happy?

JeeBee mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri Jul 28 21:55:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 29 Jul 2006 - 08:17:10 EST.

Mailing list information is available at Please read the posting guide before posting to the list.