Supposed I have the number $N$ that is composed from the digits $\underline{d_1d_2d_3...d_i}$, then I define $N^*$ as $d_1+d_2+d_3+...+d_i$, where $d_i$ can take integer values only from $0$ to $9$. Relation between $d_i$ with $N^*$ and $N$ can be shown by the following equations:
$$N=\sum_{j=1}^i 10^{i-j}d_j$$ $$N^*=\sum_{j=1}^i d_j$$
So for $N=1121221121$, $N^*=1+1+2+1+2+2+1+1+2+1=a_1+2a_2$, where $a_1=6$ and $a_2=4$. The lowercase letter $a$ represents frequency of occurance of its subscript number. In general, as $d_i$ take only $0$ to $9$, one can write $N^*$ as;
$$N^*=a_1+2a_2+3a_3+4a_4+5a_5+6a_6+7a_7+8a_8+9a_9$$
Question: For $N=1121221121$ for instance, where $d_i$ takes $1$ or $2$ only ($N^*=a_1+2a_2$), are there any formula or other expression for $a_1$ and $a_2$ with $N^*=a_1+2a_2$ which can find values of $a_1$ and $a_2$?
$\mathbf{EDIT:}$
$N^*$ is just a solution I introduced to myself to find how many $1$s and $2$s are in $N$. Other solutions to study the digit frequency of $N$ will solve the problem as well. The goal is to find a function $f_1(N)$ that tells how many $1$s are in $N$ for example. And a function $f_{d_i}(N)=a_{d_i}$ that counts how many digit $d_i$ are found in $N$.
You can just look at each digit in $n$ and check if it is equal to $d$.
Another way to say this is:
$$ f_d(n)=\sum_{k=0}^{\left\lfloor \log_{10} n \right\rfloor} \delta_{d}\left( \left\lfloor \frac{n}{10^k} \right\rfloor \bmod 10\right) $$
Note that "$\left\lfloor \log_{10} n \right\rfloor +1$" is the number of digits of a number $n$.
Note that "$\left\lfloor \frac{n}{10^k} \right\rfloor \bmod 10$" extracts the $k$th digit, $k=0,\dots,\left\lfloor \log_{10} n \right\rfloor$.
Note that $\delta_d(x)=\begin{cases}1,&\text{if } d=x\\0,&\text{if } d\ne x\end{cases}$, also known as Kronecker delta.