Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(Rcpp)
- cppFunction('
- NumericMatrix imembrandc(int n, int k) {
- NumericMatrix u( n , k );
- IntegerVector sequ = seq(1,100);
- NumericVector sampled;
- for (int i=0; i < k; ++i) {
- sampled = sample(sequ, n);
- u(_,i) = sampled / sum(sampled);
- }
- if (is_true(any(rowSums(u) != 1))) {
- u(_,1) = u(_,1) + (1 - rowSums(u));
- }
- return(u);
- }')
- res = imembrandc(n = 10, k = 5)
- rowSums(res)
- rowSums(res) == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement