Re: [R] convert decimals to fractions - sorted

From: JeeBee <JeeBee_at_troefpunt.nl>
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 <- as.data.frame(table(df))

# 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,

        fracs=as.character(as.fractions(as.numeric(as.character(tmp1$V2)))))

# Finally hide that sort colum if you want

( tmp2[-2] )

# Everybody happy?

JeeBee



R-help@stat.math.ethz.ch 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. 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.