Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.A41.4.63.0509201337500.214750@acsrs3.bu.edu>
Date: 2005-09-20T17:43:49Z
From: Qiong Yang
Subject: How to exclude a level from a factor
In-Reply-To: <433043C9.60506@pdf.com>

Problem solved. Thanks a lot for your replies!

> x
[1] a b c
Levels: a b c

> factor(as.character(x),exclude="c")
[1] a    b    <NA>
Levels: a b

"exclude=" option may not work on factors.
One has to convert the factor to character first.

Qiong

On Tue, 20 Sep 2005, Sundar Dorai-Raj wrote:

>
>
> Qiong Yang wrote:
>> Hi,
>> 
>> I could not use 'exlcude=' option in factor()
>> to exclude a level from a existing factor.
>> 
>> x is a factor:
>> 
>> 
>>> x
>> 
>> [1] a b c
>> Levels: a b c
>> 
>> 
>>> factor(x,exclude="c")
>> 
>> [1] a b c
>> Levels: a b c
>> Warning message:
>> NAs introduced by coercion
>> 
>> However, "c" is not coded as NA.
>> 
>> The following does not work either:
>> 
>> 
>>> factor(x,exclude=factor("c",levels=c("a","b","c")))
>> 
>> [1] a b c
>> Levels: a b c
>> 
>> 
>> What's wrong with my codes?
>> 
>
>
> I think you want:
>
> x <- factor(letters[1:3])
> factor(as.character(x), exclude = "c")
>
> HTH,
> --sundar
>