Re: [R] convert decimals to fractions - sorted

From: Muhammad Subianto <msubianto_at_gmail.com>
Date: Sat 29 Jul 2006 - 06:47:25 EST

Dear JeeBee and all,
It is nice. Thanks you very much.
I must learn much more about ?as.fractions, ?as.numeric, ?as.character and ?table functions.

Best wishes, Muhammad Subianto

On 7/28/06, JeeBee <JeeBee@troefpunt.nl> wrote:
>
> 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.
>



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 Sat Jul 29 06:54:38 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:23 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.