[R] i param in "for" loop does not takes zeros?

From: Francisco J. Zagmutt <gerifalte28_at_hotmail.com>
Date: Thu 14 Apr 2005 - 07:25:27 EST


Hi all

Is there any reason why the parameter i in a "for" loop ignores a value of zero? For example

sim=c()
p=.2
for(i in 0:5)
  {sim[i]=dbinom(i,5,p)
  }

sim
[1] 0.40960 0.20480 0.05120 0.00640 0.00032

In this example the quantile i= 0 was ignored since dbinom(0,5,p)
[1] 0.32768

The same behaviour occurs if I use a while loop to perform the same calculation:
sim=c()
p=.2
i=0
while(i <6)
  {sim[i]=dbinom(i,5,p)
  i=i+1
  }
sim
[1] 0.40960 0.20480 0.05120 0.00640 0.00032

How can I perform a loop passing a zero value parameter? I know I can use an if statement for i<=0 but I was wondering why the loop is ignoring the zero value.

Many thanks!

Francisco



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Apr 14 07:30:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:08 EST