[R] R question

Bill Venables William.Venables at cmis.CSIRO.AU
Fri Dec 17 01:32:05 CET 1999

> Dear Dr. Ihaka, Thank you for your reply. The example below was merely an
> example. The reality is more complex. I have a function called h which
> takes a scalar argument and returns an lm object. In the loop I was hoping
> h(l[i]) would be interpreted as h of the scalar argument, but instead I
> get:
> Error in h(l[i]) : Object "l" not found
> I will probably give up on this method for the time being, and try another
> method, since I pressed for time.
> My failed script is below in case anybody is willing to take a look.
>                                        Sincerely, Faheem Mitha.

Normally I bite my tongue and keep going when I see questions
like these but this time let me make a general observation and
offer some downright paternalistic advice (as befits someone like
me - if you have ever seen me you will know I look very much like
Father Christmas...)

SAS, SPSS and other similar systems provide easy ways of handling
sequences of objects with patterned names like L1, L2, ...  The S
languages (like R) do not: they provide ways but they are not
elementary.  This is because the S languages encourage you to
approach the problem in a different way: rather than use a
sequence of objects with structured names, but all the objects
together in a list structure and use the index: so for L2 you use
L[2], but with luck you won't have to single it out yourself at all.

There are good reasons for this.  The S languages discourage
explicit loops and provide features like vectorization and
operators like the lapply()-family that do iterative computations
more efficiently.  In the S languages you are always encouraged
to take the "whole object view", to quote John Chambers, to deal
with the structure as a whole and not to take an iterative view.

I'm willing to bet that most of these questions come from people
who are (usually unwilling) refugees from another system like SAS
or SPSS trying to make an S language system work in a way to
which they have become accustomed.  (The non-working script that
accompanied this note was a very clear example of this philosophy
in action.)  Changing ways of thinking about a problem is always
unappealing and often difficult.  I have no words of comfort, I
regret to say: the only viable option is to learn how to use the
new system properly and to forget the old.  I had to do it with glim, genstat and matlab so I know it can be done.  The only consolation
I can offer is that when you do overcome the initial hurdle life
becomes so much simpler and the feeling you get when you find the
system is working for you at last (and not the other way round)
is an incredible high point!

All the best for the season,
Bill Venables.
Bill Venables, Statistician, CMIS Environmetrics Project.

Physical address:                            Postal address:
CSIRO Marine Laboratories,                   PO Box 120,       
233 Middle St, Cleveland, Queensland         Cleveland, Qld, 4163
AUSTRALIA                                    AUSTRALIA

Telephone: +61 7 3826 7251     Email: Bill.Venables at cmis.csiro.au     
      Fax: +61 7 3826 7304

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list