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]]