Thomas Hopper
2005-Mar-20 22:23 UTC
[R] Generating Interaction Factors (combinations of Data Frame columns)
I'm starting to do a fair amount of DOE in my day job and need to generate full- and fractional-factorial designs. One of the things I'd like to do is generate all possible interaction effects, given the main effects. I've been searching through the documentation, packages and mail list archives, but the closest I can find are combin() in package combinat and combine() and combinations() in gregsmisc, none of which actually produces the results I want. Given a data frame with columns labeled A, B, C and D, I would like to generate a data frame with columns that are the combination of each of the columns in the original data frame. The output columns would be A*B, A*C, A*D, A*E, A*B*C, A*B*D,..., A*B*C*D. Alternatively, I'd want to generate the interactions for a given level (2-factor or 3-factor). If such a function already exists, I'd be more than happy to use it. If it doesn't, I can write it, but I would appreciate a little help with the algorithm for generating the combinations...how do I loop through the given factors to generate all possible combinations? Thanks, Tom
Rolf Turner
2005-Mar-20 22:34 UTC
[R] Generating Interaction Factors (combinations of Data Frame columns)
?model.matrix
Kjetil Brinchmann Halvorsen
2005-Mar-21 17:13 UTC
[R] Generating Interaction Factors (combinations of Data Frame columns)
Thomas Hopper wrote:> I'm starting to do a fair amount of DOE in my day job and need to > generate full- and fractional-factorial designs. > > One of the things I'd like to do is generate all possible interaction > effects, given the main effects. I've been searching through the > documentation, packages and mail list archives, but the closest I can > find are combin() in package combinat and combine() and combinations() > in gregsmisc, none of which actually produces the results I want. > > Given a data frame with columns labeled A, B, C and D, I would like to > generate a data frame with columns that are the combination of each of > the columns in the original data frame. The output columns would be > A*B, A*C, A*D, A*E, A*B*C, A*B*D,..., A*B*C*D. > > Alternatively, I'd want to generate the interactions for a given level > (2-factor or 3-factor). > > If such a function already exists, I'd be more than happy to use it. > > If it doesn't, I can write it, but I would appreciate a little help > with the algorithm for generating the combinations...how do I loop > through the given factors to generate all possible combinations? > > Thanks, > > Tom > > ______________________________________________ > 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 > > >library(BHH2) # on CRAN ?ffDesMatrix ?ffFullMatrix -- Kjetil Halvorsen. Peace is the most effective weapon of mass construction. -- Mahdi Elmandjra -- No virus found in this outgoing message. Checked by AVG Anti-Virus.
Maybe Matching Threads
- fractional factorial design in R
- BBH2 and FrF2 packages
- Which is the easiest (most elegant) way to force "aov" to treat numerical variables as categorical ?
- How to embed residual dot plots of BHH2::anovaPlot(...) into plotMeans(...)?
- Can R make an usual dotplot