Skip to content
Prev 4068 / 398506 Next

R question

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.