Message-ID: <20110425212131.GA31042@praha1.ff.cuni.cz>
Date: 2011-04-25T21:21:31Z
From: Petr Savicky
Subject: Factor function
In-Reply-To: <1303761220026-3473984.post@n4.nabble.com>
On Mon, Apr 25, 2011 at 12:53:40PM -0700, Lisa wrote:
> Dear All,
>
> I just want to remove ?NA? from the levels of a factor. For example:
>
> d<-data.frame(matrix(c("ww","ww","xx","yy","ww","yy","xx","yy","NA"),
> ncol=3, byrow=TRUE))
>
> > factor(d[, 3], exclude=NA)
> [1] xx yy NA
> Levels: NA xx yy
>
> But ?NA? is still listed in the levels. How can I solve this problem?
The column d[, 3] is already a factor. It is possible to avoid
this using
d<-data.frame(matrix(c("ww","ww","xx","yy","ww","yy","xx","yy","NA"),
ncol=3, byrow=TRUE), stringsAsFactors=FALSE)
Then, we get
factor(d[, 3], exclude="NA")
[1] xx yy <NA>
Levels: xx yy
Hope this helps.
Petr Savicky.