Hello list.
I feel like an idiot.
There exists a method called expand.grid which, from the documentation,
appears to do just what I want, but then it doesn't, and I can't get it to
behave.
Given a dataframe
dfr<-data.frame(c1=c("a", "b", NA, "a", "a"), c2=c("d", NA, "d", "e", "e"),
c3=c("g", "h", "i", "j", "k"))
I would like to have a dataframe with all (unique) combinations of all the
factors present.
In fact, I would like a simple solution for these two cases: given the three
factor columns above, I would like both all _possible_ combinations of the
factor levels, and all _present_ combinations of the factor levels (e.g. if
I would do this for the first 4 rows of dfr, it would contain no
combinations with c3="k"). It would also be nice to be able to choose
whether or not NA's are included.
I'm convinced that some package holds a readymade solution, and I'm trying
to switch from always writing my own stuff (get the number of levels per
column, then use some apply magic) to using what is there, so thanks for any
hints,
Nick Sabbe
--
ping: nick.sabbe@ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36
-- Do Not Disapprove
[[alternative HTML version deleted]]