Message-ID: <FA0F39D3-A8EE-47A9-80D6-C1EA49BD9C36@tin.it>
Date: 2005-08-03T22:25:15Z
From: Simone Gabbriellini
Subject: problem with for()
In-Reply-To: <1123105050.4100.13.camel@localhost.localdomain>
how can I have a 0 evaluated in my loop then?
it is important for my algorithm
do you have any hints?
simone
Il giorno 03/ago/05, alle ore 23:37, Marc Schwartz ha scritto:
> On Wed, 2005-08-03 at 23:24 +0200, Simone Gabbriellini wrote:
>
>> 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
>>
>> thank you,
>> simone
>>
>
> No....the indexing of R objects is 1 based. Thus your first loop tried
> to set i[0], which is a non-existent entry.
>
>
>> i <- 0:5
>>
>
>
>> i
>>
> [1] 0 1 2 3 4 5
>
>
>> i[0]
>>
> numeric(0)
>
>
>> i[1]
>>
> [1] 0
>
> HTH,
>
> Marc Schwartz
>
>
>
>