I am not really familiar with the theory of free $\mathbb Z$-modules so I would appreciate some help understanding this.
Let $f: \mathbb Z^3 \to \mathbb Z^3$ be the homomorphism given by the matrix $$\begin{pmatrix}1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}$$ then express the cokernel of $f$ in standard form.
Using row and column operations, the above matrix is equivalent to $$ \begin{pmatrix} 1 & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 0 \end{pmatrix}.$$
So it seems like the cokernel of $f$ should be $\mathbb{Z}_3 \oplus \mathbb Z.$
My question is, the rank of $f$ is $2$ and the rank of the target is $3$, so I expected the cokernel to be of rank $1$. But it has two basis one for $\mathbb Z_3$ and $\mathbb Z$. Is the concept of rank or dimension different from that of vector spaces for this?
If $A$ is a finitely generated abelian group, then the Structure Theorem tells us that $A$ can be written uniquely in the form $$A\cong \mathbb{Z}^r\oplus\mathbb{Z}_{m_1}\oplus\cdots \oplus \mathbb{Z}_{m_k},\qquad r\geq0, k\geq 0, 1\lt m_1\mid m_2\mid\cdots \mid m_k.$$ The rank of $A$ is then defined to be $r$; that is, the dimension of the free part of $A$.
So in your example, the rank of the cokernel is indeed equal to $1$.
Note that under the usual definition a set of elements $x_1,\ldots,x_n$ of an abelian group $A$ is independent if and only if for every integers $a_1,\ldots,a_n$, if $a_1x_1+\cdots+a_nx_n=0$, then $a_1=\cdots=a_n=0$. The rank can then be defined as maximum cardinality of an independent subsets (when the group is finitely generated, at any rate). No torsion element can be in an independent set, so $\mathbb{Z}_3\oplus\mathbb{Z}$ would not have an independent set of cardinality two.