[R] Subset and levels

Florent Bresson f_bresson at yahoo.fr
Mon Nov 6 18:14:30 CET 2006


Hi, I've got a very simple problem but cannot find the solution. I'm using two data frames (say X and Y) and I want to get a subset of one according to the different levels of a variable "code" of the other data frame. I tried something like
Z    <-    subset(X, code==levels(Y$code))        (1)

but it does not work. I do not want to do something like
Z    <-    subset(X,code==level1 | code==level2...)

because length(levels(Y$code)) is 130. So what's wrong with (1)    ?

Thanks



More information about the R-help mailing list