[R] decimal number format as quarter

peter dalgaard pdalgd at gmail.com
Wed Feb 8 16:14:57 CET 2012


On Feb 8, 2012, at 15:48 , David Reiner wrote:

> Looks like something priced in eighths; we deal with similar notation for bonds and similar instruments.
> 
>> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
>> as.integer(x)+10*(x-as.integer(x))/8
> [1] 2.25 2.50 2.75 3.25 3.50 3.75
> 
> Adjust the 10 and 8 if you have other denominators.

For the case at hand, I expect that you can even get away with

> ceiling(x*4)/4
[1] 2.25 2.50 2.75 3.25 3.50 3.75


-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list