Skip to content

How to save an object in a function

2 messages · Prashobh Palakkeel, David Winsemius

#
This is the code for permutations from the package "gtools"

fn_perm_list <-
  function (n, r, v = 1:n)
  {
    if (r == 1)
      matrix(v, n, 1)
    else if (n == 1)
      matrix(v, 1, r)
    else {
      X <- NULL
      for (i in 1:n) X <- rbind(X, cbind(v[i], fn_perm_list(n - 1, r - 1,
v[-i])))
      X

    }

  }

How to save X as an object(matrix) while running the function












with regards,

Prashobh
#
X <- fn_perm_list(n, r, v)