[R] persistance of factor levels in a data frame

Petr Pikal petr.pikal at precheza.cz
Mon Feb 28 14:35:28 CET 2005



On 28 Feb 2005 at 14:07, Lefebure Tristan wrote:

> Hi,
> Just something I don't understand:
> 
> data <- data.frame(V1=c(1:12),F1=c(rep("a",4),rep("b",4),rep("c",4)))
> data_ac <- data[which(data$F1 !="b"), ]  levels(data_ac$F1)    
> 
> Why the level "b" is always present ?

H Tristan

from ?"[.factor"

Extract or Replace Parts of a Factor

Description:

     Extract or replace subsets of factors.

Usage:

     x[i, drop = FALSE]

     x[i] <- value

Arguments:

       x: a factor

       i: a specification of indices - see 'Extract'.

    drop: logical.  If true, unused levels are dropped.
***************************************
default is FALSE so unused levels are retained.

factor(data_ac$F1)

gives you the same factor with only existing levels.

Cheers
Petr


> 
> thanks
> 
> Tristan, R 2.0.1 for Linux Fedora 3
> 
> -- 
> ------------------------------------------------------------
> Tristan LEFEBURE
> Laboratoire d'écologie des hydrosystčmes fluviaux (UMR 5023)
> Université Lyon I - Campus de la Doua
> Bat. Darwin C 69622 Villeurbanne - France
> 
> Phone: (33) (0)4 26 23 44 02
> Fax: (33) (0)4 72 43 15 23
> 
> ______________________________________________
> R-help at 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

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list