Combination with repeated elements If I have a set of $4$ numbers, for example $(1, 2, 3, 3)$, how do I calculate the $C(4, 3)$? The order doesn't matter. So, there are three different combinations that I can get - $(1, 2, 3), (1, 3, 3)$ and $(2, 3, 3)$.
Another example, if I have the word $BABY$, how do I calculate $C(4, 2)$? The combinations that I get are - $(B, A), (B, B), (B, Y)$ and $(A, Y)$.
How do I calculate $C(n, r)$ with repeated elements? Is there a formula or a method to calculate this? Something that will work with bigger values of $n$ and $r$ as well.

With a little algebra, we can calculate the desired numbers.  We use the coefficient of operator $[x^k]$ to denote the coefficient of $x^k$ of a series. In this way we can write, for example
\begin{align*}
C(4,2)=\binom{4}{2}&=[x^2](1+x)^4\\
&=\color{blue}{[x^2]}\left(1+4x+\color{blue}{6}x^2+4x^3+1\right)\color{blue}{=6}
\end{align*}
If we consider the multiset $\{1,2,3,3\}$, we can choose $1$ zero or once, $2$ zero or once, and $3$ zero, once or twice. We encode this situation algebraically as
\begin{align*}
\underbrace{(1+x)}_{1}\underbrace{(1+x)}_{2}\underbrace{(1+x+x^2)}_{3}\tag{1}
\end{align*}
where the exponent $0,1$ or $2$ of $x$ denotes the number of occurrences of $1,2$ resp. $3$.


*

*The number of three-element subsets of the multiset $\{1,2,3,3\}$ is
\begin{align*}
\color{blue}{[x^3](1+x)^2(1+x+x^2)}&=\left([x^3]+[x^2]+[x^1]\right)(1+x)^2\tag{2}\\
&=0+1+2\\
&\,\,\color{blue}{=3}
\end{align*}
according to $|\{\{1,2,3\},\{1,3,3\},\{2,3,3\}\}|=\color{blue}{3}$.


In (2) we use the coefficient of operator rule $[x^{p-q}]A(x)=[x^p]x^qA(x)$. Similarly we consider now the multiset $\{A,B,B.Y\}$ and enocde the situation algebraically as
\begin{align*}
\underbrace{(1+x)}_{A}\underbrace{(1+x+x^2)}_{B}\underbrace{(1+x)}_{Y}\tag{1}
\end{align*}


*

*The number of two-element subsets of the multiset $\{A,B,B,Y\}$ is
\begin{align*}
\color{blue}{[x^2](1+x)^2(1+x+x^2)}&=\left([x^2]+[x^1]+[x^0]\right)(1+x)^2\\
&=1+2+1\\
&\,\,\color{blue}{=4}
\end{align*}
according to $|\{\{A,B\},\{A,Y\},\{B,B\},\{B,Y\}\}|=\color{blue}{4}$.


Note: See for instance formula (5.53) in Concrete Mathematics by R. L. Graham, D. Knuth and O. Patashnik for more information of the coefficient of operator $[x^k]$.
