r中的连续排列和组合

时间:2017-10-09 10:54:47

标签: r algorithm dataframe combinations permutation

我试图在r中创建值的连续排列,但不能根据我的需要创建它。这是预期的

ID         Val  Perm 1  Perm 2  Perm3   Perm 4  Perm 5  Perm 6  Perm 7  Perm 8  Perm 9  Perm 10 Perm 11 Perm 12 Perm 13 Perm 14 Perm 15 Perm 16 Perm 17 Perm 18 Perm 19 Perm 20 Perm 21 Perm 22 Perm 23 Perm 24 Perm 25 Perm 26 Perm 27 Perm 28 Perm 29 Perm 30 Perm 31 Perm 32 Perm 33 Perm 34 Perm 35 Perm 36
 12,000      1  Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1
 12,581      2  Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1
 12,857      2  Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1
 13,387      5  Range 3 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1
 15,846      2  Range 3 Range 3 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 3 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1
 23,387      5  Range 3 Range 3 Range 3 Range 3 Range 2 Range 2 Range 2 Range 2 Range 3 Range 3 Range 3 Range 2 Range 2 Range 2 Range 2 Range 3 Range 3 Range 2 Range 2 Range 2 Range 2 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 1 Range 1 Range 1 Range 1 Range 1 Range 1
 25,424      4  Range 3 Range 3 Range 3 Range 3 Range 3 Range 2 Range 2 Range 2 Range 3 Range 3 Range 3 Range 3 Range 2 Range 2 Range 2 Range 3 Range 3 Range 3 Range 2 Range 2 Range 2 Range 3 Range 3 Range 2 Range 2 Range 2 Range 3 Range 2 Range 2 Range 2 Range 2 Range 2 Range 2 Range 1 Range 1 Range 1
 25,424      2  Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 2 Range 2 Range 3 Range 3 Range 3 Range 3 Range 3 Range 2 Range 2 Range 3 Range 3 Range 3 Range 3 Range 2 Range 2 Range 3 Range 3 Range 3 Range 2 Range 2 Range 3 Range 3 Range 2 Range 2 Range 3 Range 2 Range 2 Range 2 Range 2 Range 1
 25,932      6  Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 2 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 2 Range 3 Range 3 Range 3 Range 3 Range 3 Range 2 Range 3 Range 3 Range 3 Range 3 Range 2 Range 3 Range 3 Range 3 Range 2 Range 3 Range 3 Range 2 Range 3 Range 2 Range 2
 25,932      1  Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3 Range 3

但我得到的其他价值如

apply(combinations(n=3,r=5,v = c("Range 1","Range 2","Range 3"),repeats.allowed = T),2,sort)
      [,1]      [,2]      [,3]      [,4]      [,5]     
 [1,] "Range 1" "Range 1" "Range 1" "Range 1" "Range 1"
 [2,] "Range 1" "Range 1" "Range 1" "Range 1" "Range 2"
 [3,] "Range 1" "Range 1" "Range 1" "Range 1" "Range 2"
 [4,] "Range 1" "Range 1" "Range 1" "Range 2" "Range 2"
 [5,] "Range 1" "Range 1" "Range 1" "Range 2" "Range 2"
 [6,] "Range 1" "Range 1" "Range 1" "Range 2" "Range 2"
 [7,] "Range 1" "Range 1" "Range 2" "Range 2" "Range 3"
 [8,] "Range 1" "Range 1" "Range 2" "Range 2" "Range 3"
 [9,] "Range 1" "Range 1" "Range 2" "Range 2" "Range 3"
[10,] "Range 1" "Range 1" "Range 2" "Range 2" "Range 3"
[11,] "Range 1" "Range 2" "Range 2" "Range 2" "Range 3"
[12,] "Range 1" "Range 2" "Range 2" "Range 3" "Range 3"
[13,] "Range 1" "Range 2" "Range 2" "Range 3" "Range 3"
[14,] "Range 1" "Range 2" "Range 2" "Range 3" "Range 3"
[15,] "Range 1" "Range 2" "Range 2" "Range 3" "Range 3"
[16,] "Range 2" "Range 2" "Range 3" "Range 3" "Range 3"
[17,] "Range 2" "Range 2" "Range 3" "Range 3" "Range 3"
[18,] "Range 2" "Range 2" "Range 3" "Range 3" "Range 3"
[19,] "Range 2" "Range 3" "Range 3" "Range 3" "Range 3"
[20,] "Range 2" "Range 3" "Range 3" "Range 3" "Range 3"
[21,] "Range 3" "Range 3" "Range 3" "Range 3" "Range 3"

准备排列列的逻辑将是排列的第一列(" Perm 1")就像保持"范围1"常数和"范围2"和"范围3"改变,"范围2"一直在增加"范围3"减少到列#34; Perm 8"并从#34; Perm 9"值"范围1"已增加1和"范围2"和"范围3"改变,"范围2"一直在增加"范围3"减少直至列#34; Perm 15"并且从" Perm 16"列"范围1"再次增加2,依此类推。

可以使用其他功能吗? 提前谢谢。

DOMNICK。

1 个答案:

答案 0 :(得分:0)

您的模式不典型。从我所知道的你的模式,你可以尝试这个自定义功能

gestureLeftArrow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftArrowGesture:)];
            [self.navigationController.navigationBar addGestureRecognizer:gestureLeftArrow];

            gestureRightArrow = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightArrowGesture:)];
            [self.navigationController.navigationBar addGestureRecognizer:gestureRightArrow];  


UIImage *image = [[UIImage imageNamed:@"hamburger-new.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIBarButtonItem *flyoutButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(showFlyoutMenu)];
        self.navigationItem.rightBarButtonItem = flyoutButton;