作者embed (暱稱是我)
看板Statistics
標題[問題] R生成所有可能的組合情況
時間Thu May 7 16:11:57 2009
想請問一下R裡面有沒有指令 可以讓我列出所有變數的可能組合情況?
例如今天我有4個variables: x1, x2, x3, x4
所以all subsets 有 2^4 = 16 的情況,如下列陳述:
零個變數: {}
一個變數: {x1}, {x2}, {x3}, {x4}
兩個變數: {x1, x2}, {x1, x3}, {x1, x4}, {x2, x3}, {x2, x4}, {x3, x4}
三個變數: {x1, x2, x3}, {x1, x2, x4}, {x1, x3, x4}, {x2, x3, x4}
四個變數: {x1, x2, x3, x4}
謝謝Orz
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.234
※ 編輯: embed 來自: 140.112.4.234 (05/07 16:12)
1F:推 bugle:x[combn(1:4,n)] # n代1,2,3,4 05/07 23:25
2F:→ bugle:得出來是四個numeric, 請再依照n去劃分 05/07 23:25
3F:→ embed:謝謝~~我終於知道combn要怎麼用了orz 05/11 16:22