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. Then I tried another way,> abs(1+52)[1] 53> cc==abs(1+52)[1] FALSE Why it is FALSE. 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, 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. Also,> c<-0.5-0.1 > n<-0.6-0.2 > n==c[1] FALSE So, is "==" comparing formula or result? Thanks, Renny [[alternative HTML version deleted]]
Hello, You assigned 53 to c, not cc. Also, take a look at this: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f On Tue, Dec 9, 2008 at 9:36 PM, Renny Li <rennyli at yahoo.com> 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. Then I tried another way, > >> abs(1+52) > [1] 53 >> cc==abs(1+52) > [1] FALSE > > Why it is FALSE. 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, 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. > > Also, >> c<-0.5-0.1 >> n<-0.6-0.2 >> n==c > [1] FALSE > > So, is "==" comparing formula or result? > > Thanks, > Renny > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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. > >
On Tue, Dec 9, 2008 at 5:36 PM, Renny Li <rennyli at yahoo.com> 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] FALSEcc is 50. bb is 1. Why do you expect 50 to equal 1 + 52? Perhaps you meant to type cc <- 53 ? Hadley -- http://had.co.nz/
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.
Apparently Analagous Threads
- Adding a line to a beside=TRUE barplot
- [LLVMdev] Researching alternative for home-grown VM
- [PATCH 1/2] nv50/ir: Add support for MAD short+IMM notation
- [LLVMdev] CriticalAntiDepBreaker rewrites a register operand of a call instruction
- ARM Backend BuildMI operand issues