[R] problem with for()

Spencer Graves spencer.graves at pdf.com
Wed Aug 3 23:43:22 CEST 2005


Hint:  help.search() -> "An Introduction to R" -> "Simple manipulations 
numbers and vectors" -> ...

spencer graves

Peter Dalgaard wrote:

> Simone Gabbriellini <ogabbrie at 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
> 
> 

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list