[R] Indexing by factor misfeature

Wilhelm B. Kloke wb at arb-phys.uni-dortmund.de
Tue Apr 20 10:49:02 CEST 2004


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.




More information about the R-help mailing list