[19036] in s-news-athena
Re: [S] Summary: Adding levels to a factor
daemon@ATHENA.MIT.EDU (Z. Todd Taylor)
Tue Aug 24 14:51:22 1999
Date: Tue, 24 Aug 1999 11:44:40 -0700 (PDT)
From: "Z. Todd Taylor" <Todd.Taylor@pnl.gov>
To: s-news@wubios.wustl.edu
Cc: todd.taylor@pnl.gov
Message-Id: <199908241844.LAA01233@aggie.pnl.gov>
I wrote:
> Hmm. na.tree.replace seems to expect a data frame, not an
> individual factor. Are you suggesting to modify that or pull
> out the relevant parts? Looking inside, the important
> expression appears to be:
>
> x <- factor(x, c(1:4, "NA"), c(levels(xx), "NA"), exclude = NULL)
>
> Beware that 1:4 hard-coded limit.
>
> Also, na.tree.replace seems to have been replaced by
> na.tree.replace.all in Splus 5.*.
Oops. The expression above applies only to the non-factors
(or level-less factors?). The functional part for factors
looks more like:
pos <- is.na(x)
cl <- class(x)
class(x) <- NULL
lev <- c(attr(x, "levels"), "NA")
x[pos] <- length(lev)
levels(x) <- lev
class(x) <- cl
which could be cut out and made into a separate function
if desired.
--Todd
--
Z. Todd Taylor
Pacific Northwest National Laboratory
Todd.Taylor@pnl.gov
Why is an 'old woman' older than an 'older woman'?
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news