Say that I have a matrix of the $n^k$ ordered lists of $k$ objects from a supply of $n$, with replacement (which I am not sure how it's called). Note that $k$ may be greater, equal, or less than $n$. Here is an example:

k <- 5 
n <- 3 

m <- expand.grid(data.frame(matrix(rep(c(1:n),k),ncol=k)))

Is there a formal way to express the number of results (i.e. rows) with $i$ unique occurrences (where $1 \le i \le n$), as a function of $k$, $n$ and $i$ ? (which is exactly what the following R command returns):

table(apply(m,1,function(x) length(unique(x)))) 

  1   2   3 
  3  90 150 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.