Hi, thank Petr for your help. I have implemented you code suggestion but there is another problem. It seems that the code: for (i in 1:m){ Z[i,,]=table(occ, data_matrix[,i]) } don't charge any values in Z. Is there some error? Thanks. Giuseppe