Here's the answer to the first part of your question:

#Decimals to fractions
frac.fun <- function(x, den){
dec <- seq(0, den) / den
nams <- paste(seq(0, den), den, sep = "/")
sapply(x, function(y) nams[which.min(abs(y - dec))])
}

frac.fun(c(0, 1, 0.8266667, .066666, 0.2666666,0.03125), 32)

To convert from fraction to decimal, I would strsplit numbers in two parts,
one integer and one fraction.

#Fractions to decimals
x <- c("2 1/32","3 7/32","4 27/32")
my.split<-strsplit(x," ")

However, I do not know how to convert a "1/32" caracter string to numeric.

Pierre


On Wed, Sep 1, 2010 at 5:22 PM, Gandhi, Puneet - RSCH AMRS <
p.gandhi@baml.com> wrote:

>
>
>
> Hi,
>
> Can any one point me to a function which converts prices in decimals to
> 32nds and vice versa.
>
> Thanks
> Puneet
>
> ----------------------------------------------------------------------
> This message w/attachments (message) is intended solely ...{{dropped:7}}
>
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

