[R] decimal number format as quarter

Arnaud Gaboury arnaud.gaboury at a2ct2.com
Wed Feb 8 15:44:33 CET 2012


TY Jim,

It do the trick.

I was trying to play without success with the format() options.
No simplest way so?

Arnaud Gaboury
 
A2CT2 Ltd.


-----Original Message-----
From: jim holtman [mailto:jholtman at gmail.com] 
Sent: mercredi 8 février 2012 15:36
To: Arnaud Gaboury
Cc: r-help at r-project.org
Subject: Re: [R] decimal number format as quarter

will this do it for you:

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> # get integer part
> x.i <- as.integer(x)
> # get fractional part
> x.f <- (x * 10) %% 10
> # new result
> result <- x.i + ifelse(x.f == 2
+                     , .25
+                     , ifelse(x.f == 4
+                         , .5
+                         , .75
+                         )
+                     )
> result
[1] 2.25 2.50 2.75 3.25 3.50 3.75
>
>

On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury <arnaud.gaboury at a2ct2.com> 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 ?
>
> TY for any help.
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> ______________________________________________
> R-help at r-project.org 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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list