Re: [R] levels of factor when subsetting the factor

From: Doran, Harold <HDoran_at_air.org>
Date: Tue 12 Sep 2006 - 15:27:55 GMT


Just add the following to your code

new.fact = fact[1:6, drop=T]

> new.fact

[1] A A A B B B
Levels: A B

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of
> Afshartous, David
> Sent: Tuesday, September 12, 2006 11:23 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] levels of factor when subsetting the factor
>
>
> All,
>
> When I take a subset of a factor the reduced factor still
> maintains all the original levels of the factor when say
> forming the key in a plot.
> The data is correct, but the variable still "remembers" the
> original levels. See below for reproducible code. Does
> anyone know how to fix this?
> cheers,
> dave
>
> fact = as.factor(c(rep("A", 3),rep("B", 3), rep("C", 3)))
> new.fact = fact[1:6]
> > new.fact
> [1] A A A B B B
> Levels: A B C ## should only show A B
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Sep 13 06:49:19 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 12 Sep 2006 - 21:01:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.