Skip to content

R question

2 messages · Bill Venables, John Logsdon

#
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.
#
Faheem and others

As another but much more lowly refugee from glim, genstat and octave
(although I still use these from time to time) I can only endorse what
Bill Venables has to say.  Even now, I find myself thinking in glim terms
(particularly when it comes to the - I think superior - indexing in glim,
and I do miss the elegance of glim's glm execution but these are
weaknesses of the S definition, not R) and it costs me time.  

You have to think in terms of structures and tools like the apply() family
to do things. Then they do work out.  Good software like R always promotes
education and thinking about the problem at hand rather than getting into
for-loops and bottom up constructions.

There is one point in your scripts that I want to warn you about - the use
of single characters such as t() or c() as functions.  I think l() gets
away with it but you will end up confusing  the issue.  In particular, you
can get an apparently meanlingless message.

Not that I always follow my own advice of course!!!

John

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._