Message-ID: <A12872756FAB8042A67B0B286A9FB21503155C58@aismsx.a-i-s.biz>
Date: 2012-02-08T14:44:33Z
From: Arnaud Gaboury
Subject: decimal number format as quarter
In-Reply-To: <CAAxdm-5o70OXX_a9uTsH0qLUVH0VvoJj3jqe5=yv1rgzQ96n4Q@mail.gmail.com>
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.