[R] Problem with modification of [.factor
David James
dj at research.bell-labs.com
Fri Jul 19 15:00:00 CEST 2002
Frank E Harrell Jr wrote:
> Under
>
> platform i586-pc-linux-gnu
> arch i586
> os linux-gnu
> system i586, linux-gnu
> status
> major 1
> minor 5.0 [1.5.1 not available for Mandrake 8.1]
> year 2002
> month 04
> day 29
> language R
>
> when I modify [.factor to change the default drop=FALSE to drop=TRUE as such:
>
> '[.factor' <- function(x, i, drop=TRUE) {
> y <- NextMethod("[")
> class(y) <- class(x)
> attr(y, "contrasts") <- attr(x, "contrasts")
> attr(y, "levels") <- attr(x, "levels")
> if (drop)
> factor(y)
> else y
> }
A simple fix is 'x <- unclass(x)' prior to NextMethod(). But before
doing this, I'd consider Prof. Ripley's comments on this topic extremely
carefully.
>
> I get a recursion error:
>
> > x <- factor(1:2,1:2,c('a','b'))
> > x[]
>
> Error in inherits(x, "factor") : evaluation is nested too deeply: infinite recursion?
>
> If anyone has an explanation/fix I would appreciate getting it.
>
> Thanks in advance, -Frank
> --
> Frank E Harrell Jr Prof. of Biostatistics & Statistics
> Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
> U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
David A. James
Statistics Research, Room 2C-253 Phone: (908) 582-3082
Bell Labs, Lucent Technologies Fax: (908) 582-3340
Murray Hill, NJ 09794-0636
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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