[R] decimal number format as quarter

Petr Savicky savicky at cs.cas.cz
Wed Feb 8 16:21:24 CET 2012


On Wed, Feb 08, 2012 at 03:12:56PM +0100, Arnaud Gaboury wrote:
> Hello,
> 
> I have to deal with numbers with a decimal part as quarter, coming from two systems with different way to show decimals. I need to tell R these are in fact the same number.
> 
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
> 
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?

Hello:

Try the following.

  vec <- c(2, 2.2, 2.4, 2.6, 3, 3.2, 3.4, 3.6)
  round(4*(vec + 0.1))/4

  [1] 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75

Hope this helps.

Petr Savicky.



More information about the R-help mailing list