[R] Zero Index Origin?
ggrothendieck at myway.com
Thu Apr 1 05:45:53 CEST 2004
Bob Cain <arcane <at> arcanemethods.com> writes:
... zero origin ...
It occurred to me that perhaps the point about classes could be
framed somewhat differently.
I think you have an implicit assumption that vectors, matrices
and arrays in general should be used to represent the objects
that you are interested in for your DSP work.
This is an understandable assumption coming from an APL background
where everything is an array but in R and other OO languages you
can define your own classes that behave the way you want. The
objective is not to shoehorn your application into preset structures
like you do in APL but rather in R it is possible to create a model
through its class and other facilities that closely models your domain.
Even within the classes offered to you out-of-the-box I wonder
if time series rather than vectors are not the appropriate
class? For example, even if we accept indexing as the way to
go for the moment, a time series might have an advantage.
Furthermore, are you sure you want to loop over 0:length(whatever)-1.
Maybe that paradigm is just ingrained through lack of access to
anything better. Might it not really be better to iterate over
time: t0, t0+deltat, ..., t1 in which 0-origin is inadequate so
why stop there when you can have it all?
The point is that rather than shoehorn your problem into vectors,
you could use the facilities of R (either ones that are already there
or ones you create for DSP) to act in precisely the right way and
in the process get rid of the baggage that comes with being forced
to iterate over 1,2,3,... or over 0,1,2,... Going past that you
can go past iteration altogether and start dealing with whole objects
Finally, if you really approach this as how to set up one or more
DSP clases, the solution you come up with may not be to create a 0-origin
vector class but rather it should involve really understanding and modeling
your problem domain in a way which was never possible with the
limited modelling facilities of APL in which everything is an array.
Its been said that you can program FORTRAN in any language. In the
context of this discussion perhaps it could be said that you can
program in an APL-like style in R but to really get the benefit of
R you have to move to the appropriate program design style. (I am
not putting down APL which is one of the most brilliant computer
science achievements I have ever seen -- just pointing out where to
go from there.)
Of course the above is motherhood and some specific examples
might put a sharper edge to the discussion.
More information about the R-help