[19032] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Summary: Adding levels to a factor

daemon@ATHENA.MIT.EDU (Prof Brian D Ripley)
Tue Aug 24 14:01:38 1999

Date: Tue, 24 Aug 1999 18:54:44 +0100 (BST)
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
To: =?iso-8859-1?Q?G=E9rald_Jean?= <Gerald.Jean@spgdag.ca>
Cc: s-news@wubios.wustl.edu
In-Reply-To: <852567D7.0060CB6B.00@mail.spgdag.com>
Message-Id: <Pine.GSO.4.05.9908241852230.5136-100000@auk.stats>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
Content-Transfer-Encoding: 8bit


On Tue, 24 Aug 1999, [iso-8859-1] Gérald Jean wrote:

> 
> Thanks to all who responded (Todd Taylor, Keenan Sean, Samuel Buttrey,
> Leonid Gibiansky, S.D. Byers, Bill Dunlap, Don McKenzie and Yuelin Li)  the
> original message follows.   All suggested a similar approach, i.e. first
> convert the factor to character and then convert back to factor adding the
> new level in the process; one thing I forgot to say is that I was not
> creating the factor variables myself, there is several with the same
> problem, they were created by someone else in a SAS program and I imported
> the data set using Frank Harrel's "sas.get" function.  Here is an exemple
> solution from Todd Taylor:
> 
>  new <- factor(as.character(old),
>                 levels=c(levels(old), ""),
>                 labels=c(levels(old), "Missing")
>                )
> 
> Again thanks to all,

Rather than re-invent the wheel, one could note that na.tree.replace
adjust all the factors in a data frame to have level "NA" if needed.
Its code does not convert to character and back. However, you could
just use it!

-- 
Brian D. Ripley,                  ripley@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

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

home help back first fref pref prev next nref lref last post