[R] Significant digits for checking values of variable?
David Afshartous
dafshartous at med.miami.edu
Wed Aug 27 18:13:38 CEST 2008
Thanks. Is there simple way around this for simple checking of single
values? The all.equal() mentioned in the FAQ doesn't seem appropriate.
X = c(1.2, 2)
> X.new = X -1
> X == 1.2
[1] TRUE FALSE
> X.new == .2
[1] FALSE FALSE
On 8/27/08 11:47 AM, "jim holtman" <jholtman at gmail.com> wrote:
> FAQ 7.31
>
> On Wed, Aug 27, 2008 at 11:51 AM, David Afshartous
> <dafshartous at med.miami.edu> wrote:
>>
>> All,
>>
>> I'm witnessing some strange behavior when checking the values of one of my
>> variables. My guess is that it has something to do with the number of
>> significant digits being represented, but perhaps not as my variable was
>> created from other variables that only had one decimal place. See below.
>> I'm sure this is something basic, any suggestions much appreciated.
>>
>> Cheers,
>> David
>>
>>
>>> visit.2.SEK.delta.baseline
>> [1] 0.1 -0.7 0.8 -0.1 -0.5 0.8 0.7 0.2 0.4 0.3 0.6 0.6 0.3 0.8
>> 0.8 0.3 0.4 0.8
>>> visit.2.SEK.delta.baseline > 0
>> [1] TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
>> TRUE TRUE TRUE TRUE TRUE TRUE
>>> visit.2.SEK.delta.baseline == .8
>> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>> FALSE FALSE FALSE FALSE FALSE FALSE
>> ### but some of the values are equal to .8
>>
>> ## here it is okay when I try to reproduce
>>> junk = c(0.1, -0.7,0.8, -0.1, -0.5, 0.8, 0.7, 0.2, 0.4, 0.3, 0.6,
>>> 0.6,
>> 0.3, 0.8, 0.8, 0.3, 0.4, 0.8 )
>>> junk == .8
>> [1] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
>> FALSE TRUE TRUE FALSE FALSE TRUE
>>
>> ______________________________________________
>> 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.
>>
>
>
More information about the R-help
mailing list