Creating Dataframes of all Possible Combinations without Repetition of Columns with cbind

谁说我不能喝 提交于 2019-12-10 23:04:59

问题


I have 3 data frames that each look like this:

head(New_Re)

           JPM.GBI.GLOBAL MSCI.WORLD.U   MSCI.EM.U WORLD.DS.Market EMERGING.MARKETS.DS   S.P.GSCI HFRI.FUND.WEIGHTED
2000-01-31    -0.23666947  -0.68583345  0.07151953      -0.5730685          0.27303054  0.8676359         0.07679939
2000-02-29    -0.06022908   0.03385849  0.15848440       0.1591570         -0.06121937  0.7497046         0.73921129
2000-03-31     0.34922825   0.83091828  0.05856337       0.6840922          0.12306658 -0.1392837         0.11159392
2000-04-28    -0.36499225  -0.50602011 -1.13751290      -0.7176648         -1.18921618 -0.1092962        -0.34199635
2000-05-31     0.08762909  -0.30232789 -0.49610312      -0.4407889         -0.48766971  1.3436823        -0.23520005
2000-06-30     0.29135209   0.40572518  0.42269891       0.5262464          0.34889766  0.8552101         0.44159731
           MSCI.WORLD.REAL WORLD.DS.Real WORLD.DS.REITs Risky_Asset
2000-01-31      -0.4797486    -0.3988462      0.2889378  -0.7962431
2000-02-29      -0.5963240    -0.7009993     -0.7454474  -0.3238034
2000-03-31       0.9327900     0.7215466      0.8258081   4.4983235
2000-04-28      -0.4948475    -0.3721225      0.8673545  -4.3663143
2000-05-31      -1.1066985    -0.6532877      0.1393459  -2.1514186
2000-06-30       0.6890960     0.9116872      0.2476261   5.1401370

I want to be able to generate ALL possible data frames that can be made from the combination of these data frames, e.g. each column on its own, binded with one other column, 2 other columns, etc. I've looked at combn, but it needs an m input of r number of elements to choose. I want to be able to automatically generate all different numbers of combinations, without allowing repetitions. For example if I had columns A, B and C, I want to be able to generate data frames comprised of :

 ('A',),
 ('B',),
 ('C',),
 ('D',),
 ('A', 'B'),
 ('A', 'C'),
 ('A', 'D'),
 ('B', 'C'),
 ('B', 'D'),
 ('C', 'D'),
 ('A', 'B', 'C'),
 ('A', 'B', 'D'),
 ('A', 'C', 'D'),
 ('B', 'C', 'D'),
 ('A', 'B', 'C', 'D')]

if can be done with combn would be fine, I just dont know how. Any ideas would be appreciated.

来源:https://stackoverflow.com/questions/46652276/creating-dataframes-of-all-possible-combinations-without-repetition-of-columns-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!