[R] Indexing by factor misfeature
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Apr 20 11:00:41 CEST 2004
This *is* a documented feature: see ?Extract.
I am afraid your `of course' is completely non-obvious to me. I would
object strongly to code written to use a documented feature issuing a
warning.
On Tue, 20 Apr 2004, Wilhelm B. Kloke wrote:
> Yesterday I was biten by a feature, which I find too dangerous.
>
> I wanted to use a factor `Subject´ as index into a data frame, whose row
> names were the levels of this factor. So there a 2 different possible
> interpretations of this: Either Subject is coerced to numeric or to
> character. The intended interpretation was, of course, `as.character(Subject)'.
> R did `as.numeric(Subject)´. This will not cause a semantic error, when
> the levels of Subject happen to be in numeric order; so it will be
> unnoticed quite often.
>
> I propose to issue a warning whenever a factor is implicitly coerced,
> at least in an ambiguous context.
--
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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list