Displaying 20 results from an estimated 6000 matches similar to: "arithmetic and logical operators"
2009 Apr 17
3
Modular Arithmetic Error?
Hi,
I'm using the '%%' operator in some code, and am running into the following erroneous outcome:
> 1.2 %% 0.2
[1] 0.2
Unless I'm very mistaken, the result should be 0 (indeed, 12 %% 2 does result in 0). Furthermore:
> 1.20000000000000001 %% 0.2
[1] 0.2
> (1.2+1e17) %% .2
[1] 0
Warning message:
probable complete loss of accuracy in modulus
(Warning
2008 Dec 05
3
Logical inconsistency
Dear colleagues
Please could someone kindly explain the following inconsistencies I've discovered when performing logical calculations in R:
8.8 - 7.8 > 1
> TRUE
8.3 - 7.3 > 1
> TRUE
Thank you,
Emma Jane
[[alternative HTML version deleted]]
2009 Jun 08
4
seq(...) strange logical value
Do you heve any idea why I get after this instruction everywhere false?
> seq (0, 1, by=0.1) == 0.3
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
But after different step it's ok:
> seq(0, 1, by=0.1) == 0.4
[1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
--
View this message in context:
2008 Mar 03
7
help for the first poster- a simple question
Hi, there,
I cannot get accurate value for calculation.
for example:
ld<-sqrt(1*0.05*0.95*0.05*0.95)
0.05*0.95-ld=-6.938894e-18
0.05*0.95-ld==0 is False.
I met this problem in my program, how can I handle it. Thanks.
xj.
2009 Aug 01
5
incorrect result (41/10-1/10)%%1 (PR#13863)
Full_Name: jan hattendorf
Version: 2.9.0
OS: XP
Submission from: (NULL) (213.3.108.185)
I get an incorrect result for
(41/10-1/10)%%1
[1] 1
The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...)
test <- rep(NA, 1000)
for(i in 1:1000){
test[i] <- i/10-1/10
}
test[test%%1==0]
2017 May 24
1
precision of do_arith() in arithmetic.c
To the R development team:
First of all, thank you so much for maintaining wonderful R software.
Perhaps, Dr. Ahn has just reported an error on the wilcox.test() function,
and suggesting that an error may arise from abs() and rank().
I just had a quick check that the problem may come from the precision of
the results of arithmetic functions.
87.7-89.1+1.4
# > 87.7-89.1+1.4
# [1]
2008 Apr 24
2
problem with "which"
Hi,
I'm having trouble with the "which" or the "seq" function, I'm not sure.
Here's an example :
> lat=seq(1,2,by=0.1)
> lat
[1] 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0
> which(lat==1)
[1] 1
> which(lat==1.1)
[1] 2
> which(lat==1.2)
[1] 3
> which(lat==1.3)
[1] 4
> which(lat==1.4)
[1] 5
> which(lat==1.5)
[1] 6
>
2013 Mar 06
3
About basic logical operators
Hello everyone,
I have a basic question regarding logical operators.
> x<-seq(-1,1,by=0.02)
> x
[1] -1.00 -0.98 -0.96 -0.94 -0.92 -0.90 -0.88 -0.86 -0.84 -0.82 -0.80 -0.78
[13] -0.76 -0.74 -0.72 -0.70 -0.68 -0.66 -0.64 -0.62 -0.60 -0.58 -0.56 -0.54
[25] -0.52 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30
[37] -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16
2009 Aug 10
3
Bug in "seq" (or a "feature") ?
(I use R 2.9.1 with win XP)
If I run this code:
seq(-0.1,.9, by = .05)[seq(-0.1,.9, by = .05) <= 0.5]
I get this output:
[1] -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45
Why is 0.50 not in the results ?
(It seems that it gives a slightly bigger number then 0.5 but I don't
understand why it does that)
Where as if I try:
seq(-0.1,.9, by = .05)[seq(-0.1,.9, by = .05) <=
2017 Jun 07
3
An R question
Hi all,
In checking my R codes, I encountered the following problem. Is there a
way to fix this?
I tried to specify options(digits=). I did not fix the problem.
Thanks so much for your help!
Hanna
> cdf(pmass)[2,2]==pcum[2,2][1] FALSE> cdf(pmass)[2,2][1] 0.9999758> pcum[2,2][1] 0.9999758
[[alternative HTML version deleted]]
2008 Nov 07
2
Mismatch in logical result?
Hi R,
I have certain checkings, which gives FALSE, but actually it is true. Why does this happen? Note that the equations that I am checking below are not even the case of recurring decimals...
> 1.4^2 == 1.96
[1] FALSE
> 1.2^3==1.728
[1] FALSE
Thanks in advance, Shubha
Shubha Karanth | Amba Research
Ph +91 80 3980 8031 | Mob +91 94 4886 4510
Bangalore * Colombo *
2010 Dec 20
6
sample() issue
> length(sample(25000, 25000*(1-.55)))
[1] 11249
> 25000*(1-.55)
[1] 11250
> length(sample(25000, 11250))
[1] 11250
> length(sample(25000, 25000*.45))
[1] 11250
So the question is, why do I get 11249 out of the first command and not
11250? I can't figure this one out.
Thanks
Cory
[[alternative HTML version deleted]]
2006 Jul 07
2
BUG in " == " ? (PR#9065)
Hello,
here is the version of R that I use :
> version
_
platform i486-pc-linux-gnu
arch i486
os linux-gnu
system i486, linux-gnu
status
major 2
minor 3.1
year 2006
month 06
day 01
svn rev 38247
language R
version.string Version 2.3.1 (2006-06-01)
And here is one of the sequences of
2009 Sep 13
2
How can I get "predict.lm" results with manual calculations ? (a floating point problem)
Hello dear r-help group
I am turning for you for help with FAQ number 7.31: "Why doesn't R think
these numbers are equal?"
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
*My story* is this:
I wish to run many lm predictions and need to have them run fast.
Using predict.lm is relatively slow, so I tried having it run faster by
2009 Jun 19
1
cut with floating point, a bug?
With floating point numbers I'm seeing 'cut' putting values in the wrong
bands. An example below places 0.3 in (0.3,0.6] i.e. 0.3 > 0.3.
> x = 1:5*.1
> x
[1] 0.1 0.2 0.3 0.4 0.5
> cut(x, br=c(0,.3,.6))
[1] (0,0.3] (0,0.3] (0.3,0.6] (0.3,0.6] (0.3,0.6]
Levels: (0,0.3] (0.3,0.6]
I'm sure this is probably the same issue documented in the FAQ (7.31 Why
doesn't R
2017 Jun 07
0
An R question
Hi,
Check the FAQ 7.31
https://cran.rstudio.com/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
And read the posting guide too...
https://www.r-project.org/posting-guide.html
HTH,
Ivan
--
Dr. Ivan Calandra
TraCEr, Laboratory for Traceology and Controlled Experiments
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567
2010 Mar 31
1
Weird R behaviour?
Dear list,
I have observed a weird behaviour from R --- apologies if I am missing
something obvious!
df3f826f28
df3f826f28
Say you type in R:
>c.preec <- 10074
>c.gd <- 2200
>p1 <- .2
>c.neo <- p1*9451 + (1-p1)*3883
>n.preec <- 3710
>n.gd <- 2650
>n.neo <- 2120
>n.pcos <- 53000
>unit.met <- 94
>cost.met <- 94*n.pcos
>effect <-
2007 Jan 20
4
Question about converting from square roots to decimals and back
Hi,
I apologize if there is a simple answer to this question that I've
missed. I did search the mailing list but I might not have used the
right keywords. Why does sum(A3^2) give the result of 1, but
sum(A3^2)==1 give the result of FALSE?
> A3<-matrix(nrow=3,c(1/(2^.5),1/(2^.5),0))
> A3
[,1]
[1,] 0.7071068
[2,] 0.7071068
[3,] 0.0000000
> sum(A3^2)
[1] 1
>
2006 Nov 22
3
odd behaviour of %%?
Dear R Helpers,
I am trying to extract the modulus from divisions by a sequence of
fractions.
I noticed that %% seems to behave inconsistently (to my untutored eye),
thus:
> 0.1%%0.1
[1] 0
> 0.2%%0.1
[1] 0
> 0.3%%0.1
[1] 0.1
> 0.4%%0.1
[1] 0
> 0.5%%0.1
[1] 0.1
> 0.6%%0.1
[1] 0.1
> 0.7%%0.1
[1] 0.1
> 0.8%%0.1
[1] 0
> 0.9%%0.1
The modulus for 0.1, 0.2, 0.4 and 0.8 is
2009 Feb 10
2
Logical Error? (PR#13516)
Full_Name: Suzi Alves Camey
Version: 2.7.2
OS:
Submission from: (NULL) (143.54.37.254)
Using the commands bellow I expected that the answer is TRUE, but it is FALSE!
P_exposicao=.9
(1-P_exposicao)==.1