Clustering and confusion matrix
Assume you clustering results are store in R. You have the partition id part_id and the real clust_id, here in a small example 

df &lt;- read.table(text = "obj,  part_id, clust_id 
X, 1, 1
Y, 2, 2
Z, 3, 3 
U, 1, 3
V, 2, 3
W, 2, 3"


Than the table will do the work for you

&gt; table(df[,c("part_id","clust_id")])

       clust_id
part_id 1 2 3
      1 1 0 1
      2 0 1 2
      3 0 0 1


UPDATE

For completeness you may also use SQL (as proposed in a comment), a sample query is shown below on a table identical to the data-frame above.

You will see imediately, that there is a limitation because you must define the exact column list in the query - so the query must be adjusted based on the cluster / partition list.

with clust_agg as (
select part_id, clust_id, count(*) cnt from clust
group by part_id, clust_id
)
select * from clust_agg
pivot(sum(cnt) clust  for (clust_id) in 
     (1 as "1",
      2 as "2",
      3 as "3"))
order by 1;
, header = TRUE, sep=",")


.

   PART_ID    1_CLUST    2_CLUST    3_CLUST
---------- ---------- ---------- ----------
         1          1                     1 
         2                     1          2 
         3                                1