[R] levels update
jim holtman
jholtman at gmail.com
Fri Dec 5 14:01:40 CET 2008
try this:
> 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)
[1] "a" "b" "c"
> my.sub$X1 <- factor(my.sub$X1)
> levels(my.sub$X1)
[1] "a" "b"
>
On Fri, Dec 5, 2008 at 7:50 AM, Antje <niederlein-rstat at yahoo.de> wrote:
> Hello,
>
> 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
>
> I guess, the solution is rather simple, but I cannot find it.
>
> Antje
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list