Message-ID: <OF81C15E04.8A3FA12C-ON80257516.0051C0DA-80257516.0051E072@hsl.gov.uk>
Date: 2008-12-05T14:54:15Z
From: Richard Cotton
Subject: levels update
In-Reply-To: <493923AC.9030606@yahoo.de>
> I hope this question is not too stupid. I would like to know how to
update
> levels after subsetting data from a data.frame.
>
> df <- data.frame(factor(c("a","a","c","b","b")), c(4,5,6,7,8),
c(9,1,2,3,4))
> names(df) <- c("X1","X2","X3")
>
> my.sub <- subset(df, X1 == "a" | X1 == "b")
> levels(my.sub$X1)
>
> # still gives me "a","b","c", though the subset does not contain entries
with
> "c" anymore
Two questions in one afternon; aren't I good to you!
levels(my.sub$X1[,drop=TRUE])
[1] "a" "b"
levels(factor(my.sub$X1))
[1] "a" "b"
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}