Re: [R] problem with for()

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 04 Aug 2005 - 07:34:10 EST

Simone Gabbriellini <ogabbrie@tin.it> writes:

> Dear list,
> can someone tell me why this two pieces of code give me the same
> results?
>
> > for(i in 0:5){ sum[i] = i }
> > sum
> [1] 1 2 3 4 5
>
> > for(i in 1:5){ sum[i] = i }
> > sum
> [1] 1 2 3 4 5
>
> shouldn't the first one be
>
> 0 1 2 3 4 5

No. Indexing starts at 1 in R.

Next, figure out this:

> sum=0
> for(i in 5:-5){ sum[i] = i }
> sum

[1] -5 -5 -5 -5 -4

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
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 Aug 04 07:37:05 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:40 EST