Search code examples
rrcpp

How to create a combination of k elements between n in Rcpp?


Good afternoon ,

We know that in R , we can retrieve all possible combinations of k elements between A = { 1 , 2 , ... , n } in that manner :

Example : A = { 1 , 2, ,3 ,4 ,5 } and K = 3

> C_wo <- combn(1:5, 3)
> C_wo
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    1    1    1    2    2    2     3
[2,]    2    2    2    3    3    4    3    3    4     4
[3,]    3    4    5    4    5    5    4    5    5     5

My question :

Is there any built-in function for Creating those combinations in rcpp ?

Thank You in advance !


Solution

  • I don't think there are such built-in Rcpp functions but these kinds of functions are implemented in {RcppAlgos}.