Is this a basic bug or something else ?
1
0
Entering edit mode
ALok ▴ 170
@alok-2917
Last seen 10.3 years ago
Dear R User, I wrote a simple script in R, just to calculate the sum of the vector ################### New<-function(n,old) { tt=0 k=length(old) for(i in 1:k) { # print(i) tt=tt+old[i] # print(tt) } print(tt) print(n) print(k) if (n == tt){ print ("A--Input is right") } if (n != tt){ print ("B--Input is wrong") } } ################### Now, I am testing it for two variable: for n=13 old1= as.vector(c(2.8,2.8,2.8,1.1,0.7,2.8)) and # I have just swaped the 3rd and 4th variable old2= c(2.8,2.8,1.1,2.8,0.7,2.8) # The first vector returns, > New(n,old1) [1] "B--Input is wrong" # While the second Vector returns, > New(n,old2) [1] "A--Input is right" Does anybody have some idea, Why is it so, Ideally both should be TRUE ????? Alok -- ************************************************************ Alok Kumar Srivastava Research Associate CRRao Advanced Institute of Mathematics, Statistics and Computer Science (AIMSCS) Gachibowli, Hyderabad 500046. ************************************************************ [[alternative HTML version deleted]]
• 1.0k views
ADD COMMENT
0
Entering edit mode
ALok ▴ 170
@alok-2917
Last seen 10.3 years ago
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https: stat.ethz.ch="" pipermail="" bioconductor="" attachments="" 20120313="" 4260c088="" attachment-0001.pl="">
ADD COMMENT
0
Entering edit mode
Hi Alok, This isn't a question for the BioC listserv, as this has nothing to do with any BioC packages. Please direct these sorts of questions to R-help. And before you go to R-help and get pasted for not understanding the intricacies of floating point arithmetic in binary systems, please see http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think- these-numbers-are-equal_003f Best, Jim On 3/13/2012 9:41 AM, ALok wrote: > Dear R User, > I wrote a simple script in R, just to calculate the sum of the vector > > ################### > New<-function(n,old) > { > tt=0 > k=length(old) > for(i in 1:k) > { > # print(i) > tt=tt+old[i] > # print(tt) > } > print(tt) > print(n) > print(k) > if (n == tt){ > print ("A--Input is right") > } > if (n != tt){ > print ("B--Input is wrong") > } > } > ################### > > Now, I am testing it for two variable: > for > > n=13 > > old1= as.vector(c(2.8,2.8,2.8,1.1,0.7,2.8)) > and > # I have just swaped the 3rd and 4th variable > old2= c(2.8,2.8,1.1,2.8,0.7,2.8) > > # The first vector returns, >> New(n,old1) > [1] "B--Input is wrong" > > # While the second Vector returns, >> New(n,old2) > [1] "A--Input is right" > > Does anybody have some idea, Why is it so, Ideally both should be TRUE ????? > > Alok > > -- James W. MacDonald, M.S. Biostatistician University of Washington Environmental and Occupational Health Sciences 4225 Roosevelt Way NE, # 100 Seattle WA 98105-6099
ADD REPLY
0
Entering edit mode
Hi Alok, This isn't a question for the BioC listserv, as this has nothing to do with any BioC packages. Please direct these sorts of questions to R-help. And before you go to R-help and get pasted for not understanding the intricacies of floating point arithmetic in binary systems, please see http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think- these-numbers-are-equal_003f Best, Jim On 3/13/2012 9:41 AM, ALok wrote: > Dear R User, > I wrote a simple script in R, just to calculate the sum of the vector > > ################### > New<-function(n,old) > { > tt=0 > k=length(old) > for(i in 1:k) > { > # print(i) > tt=tt+old[i] > # print(tt) > } > print(tt) > print(n) > print(k) > if (n == tt){ > print ("A--Input is right") > } > if (n != tt){ > print ("B--Input is wrong") > } > } > ################### > > Now, I am testing it for two variable: > for > > n=13 > > old1= as.vector(c(2.8,2.8,2.8,1.1,0.7,2.8)) > and > # I have just swaped the 3rd and 4th variable > old2= c(2.8,2.8,1.1,2.8,0.7,2.8) > > # The first vector returns, >> New(n,old1) > [1] "B--Input is wrong" > > # While the second Vector returns, >> New(n,old2) > [1] "A--Input is right" > > Does anybody have some idea, Why is it so, Ideally both should be TRUE ????? > > Alok > > -- James W. MacDonald, M.S. Biostatistician University of Washington Environmental and Occupational Health Sciences 4225 Roosevelt Way NE, # 100 Seattle WA 98105-6099
ADD REPLY

Login before adding your answer.

Traffic: 759 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6