[R] apply and factor

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Aug 10 11:04:46 CEST 2001


On Fri, 10 Aug 2001, Laurent Gautier wrote:

> Prof Brian D Ripley wrote:
> >
> > On Fri, 10 Aug 2001, Rachel Cunliffe wrote:
> >
> > > Hi again
> > >
> > > Why does this occur?
> > >
> > > > test <- apply(data,2,factor)  # where data is a data.frame
> > > > is.factor(test[,1])
> > > [1] FALSE
> >
> > test is a *matrix*, see ?apply.  No factors in matrices!
> > Using `data' as a name is probably a bad idea in R: it's an important
> > function name.
>
>
> As R extends, the number of important function names is likely to keep
> growing.
> (And I have seen Pr. Ripley mentionning more than once that one was
> overriding an important funcion).
> A good mannered user should check the existance of a function before
> choosing to giving a name... that may be not what is done...
> I was thinking of a switch to warn the user of function overriding (the
> switch could be somewhere in the options() ). The disavantage of such a
> thing might be a slowdown of the execution R scripts, and most likely
> may require a lot of implementation efforts, to set this in the existing
> code, for a rather minor improvement. An another, and may be less
> general, mecanism would be to have a special status for the functions of
> R-base. Their overriding would require an explicit statement...

There is a function conflicts() to do the checking.
Deliberate overrides are fairly common, for example when debugging,
and it is probably better to get into the habit of using conflicts()
if you get strange results.

I suspect the cost of checking would be too high.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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