[R] == operand
Ben Bolker
bolker at ufl.edu
Wed Dec 10 06:40:27 CET 2008
Renny Li wrote:
>
> Hi,
>
> I am trying to compare two values using "==" operand, please take a look
> of the following example (I copied ALL what I did here without deleting
> any line)
>
>> bb<-1
>> cc<-50
>> cc==abs(bb+52)
> [1] FALSE
>> C<-53
>> C<-53
>> c<-53
>> cc==abs(bb+52)
> [1] FALSE
>
> I am expecting to see a TRUE here.
>
Why? You are modifying the variables C and c, but not cc.
Perhaps you are confused about the == operator, which
doesn't do assignments -- it only tests equality.
Renny Li wrote:
>
> Then I tried another way,
>
>> abs(1+52)
> [1] 53
>> cc==abs(1+52)
> [1] FALSE
>
> Why it is FALSE.
>
Because cc is 50, which isn't equal to 53?
Renny Li wrote:
>
> Then I tried
>
>
>> d<-abs(b+52)
> Error: object "b" not found
>> d<-abs(bb+52)
>> d
> [1] 53
>> c==d
> [1] TRUE
>
> Now it is TRUE,
>
Which makes sense because c is 53 and d is 1+52 (i.e., 53)
Renny Li wrote:
>
> but a wired thing is as following,
>> c==abs(bb+52)
> [1] TRUE
>
> The coding "c==abs(bb+52)" is just the same from the 3line in the top, why
> 2 different results? HOWEVER, it is not repeatable, I am glad I did not
> close the window.
>
It's different, because cc and c are different
Renny Li wrote:
>
> Also,
>> c<-0.5-0.1
>> n<-0.6-0.2
>> n==c
> [1] FALSE
>
For this one, you need to see FAQ 7.31 ...
--
View this message in context: http://www.nabble.com/%3D%3D-operand-tp20928790p20929535.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list