[R] Zero Index Origin?

Peter Wolf s-plus at wiwi.uni-bielefeld.de
Wed Mar 31 11:15:47 CEST 2004


Bob Cain wrote:

>
> I'm very new to R and utterly blown away by not only the language but 
> the unbelievable set of packages and the documentation and the 
> documentation standards and...
>
> I was an early APL user and never lost my love for it and in R I find 
> most of the essential things I loved about APL except for one thing.  
> At this early stage of my learning I can't yet determine if there is a 
> way to effect what in APL was zero index origin, the ordinality of 
> indexes starts with 0 instead of 1.  Is it possible to effect that in 
> R without a lot of difficulty?
>
> I come here today from the world of DSP research and development where 
> Matlab has a near hegemony.  I see no reason whatsoever that R 
> couldn't replace it with a _far_ better and _far_ less idiosyncratic 
> framework.  I'd be interested in working on a Matlab equivalent DSP 
> package for R (if that isn't being done by someone) and one of the 
> things most criticized about Matlab from the standpoint of the DSP 
> programmer is its insistence on 1 origin indexing. Any feedback 
> greatly appreciated.
>
>
> Thanks,
>
> Bob

Hallo Bob,

in APL we control index origin by "QUAD.IO" and  QUAD.IO \in {0,1}.
Suppose within a function index origin is unknown:
a) If we want to work with origin 0 we write   x[ i  + QUAD.IO ]
b) ... with origin 1 ...  x[ i - !QUAD.IO ]  .

So set:   QUAD.IO <- 1 and use a)   ---  apl-like.

Or define an index shift function:

io.0<-function(ind) ind+1

to be able to type  x[io.0(0:5)]

I am shure that your first experiments have been to implement APL functions
like take, drop, rotate, ... and now you are looking for a more elegant way
to manage origin 0 than "+QUAD.IO".

Peter Wolf




More information about the R-help mailing list