1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rでrepeated permutation

Last updated at Posted at 2013-11-09

基本的にはexpand.gridを使えば良い。

expand.grid(rep(list(c('A','C','G','T')),2))
   Var1 Var2
1     A    A
2     C    A
3     G    A
4     T    A
5     A    C
6     C    C
7     G    C
8     T    C
9     A    G
10    C    G
11    G    G
12    T    G
13    A    T
14    C    T
15    G    T
16    T    T

「The first factors vary fastest」の挙動に不都合があるなら、こうすれば良い。

as.data.frame(t(apply(expand.grid(rep(list(c('A','C','G','T')),2)),1,rev)))
   Var2 Var1
1     A    A
2     A    C
3     A    G
4     A    T
5     C    A
6     C    C
7     C    G
8     C    T
9     G    A
10    G    C
11    G    G
12    G    T
13    T    A
14    T    C
15    T    G
16    T    T
do.call(paste,c(as.data.frame(t(apply(expand.grid(rep(list(c('A','C','G','T')),2)),1,rev))),sep=''))
 [1] "AA" "AC" "AG" "AT" "CA" "CC" "CG" "CT" "GA" "GC" "GG" "GT" "TA" "TC" "TG"
[16] "TT"

…よりよい方法をご存じの方がいらっしゃいましたらコメントいただけるとありがたいです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?