[R-sig-teaching] R Equivalent of SPSS "Split File" and "AutoRecode"

Albyn Jones jones at reed.edu
Fri Nov 14 18:26:51 CET 2008


Thanks Douglas!

I am sure that there are other ways in which my R habits are becoming
stylistically obsolete.  Is there a "manual of R style" somewhere?

albyn

On Fri, Nov 14, 2008 at 09:52:50AM -0600, Douglas Bates wrote:
> On Thu, Nov 13, 2008 at 5:31 PM, Albyn Jones <jones at reed.edu> wrote:
> >  I have no clue what "autorecode" means.  Selecting a subset of a file is
> > easy.  Suppose your data frame is named X, assuming REGION is numeric:
> >
> >    attach(X)
> >    X17 = X[REGION == 17,]
> 
> I think it is better style to use
> 
> X17 <- subset(X, REGION == 17)
> 
> Using attach/detach is discouraged these days.  The "subset" function,
> the"with" function and the general use of the formula/data arguments
> in model fitting functions and the lattice graphics functions provide
> cleaner approaches than using attach.  The problem with attach is that
> it has the side-effect of changing the search path, which is, of
> course, what it is supposed to do.  However, any functions with
> side-effects should be used only when you can't find a better
> alternative and in this case there are better alternatives.
> 
>




More information about the R-sig-teaching mailing list