How to make a pairwise comparisons matrix out of pairwise comparison values in a dataframe?

44 views Asked by At

I have a dataframe of kinship values between pairs of individuals (ibd_kinship_df):

names(ibd.coeff_df) # "ID1" "ID2" "k0" "k1" "niter" "kinship"

I want to obtain a matrix of pairwise comparisons with the individuals names as headers of the matrix (rows & columns) and the pairwise kinship values in the matrix.

I tried this code as suggested in this post --> How to make a matrix out of pairwise comparisons in R?

but it didn't work for me, I still got a dataframe and not a pairwise comparison matrix... see below:

class(ibd.coeff_df) # data.frame ibd.coeff_matrix = xtabs(kinship ~ ID1 + ID2, data=ibd.coeff_df)

class(ibd.coeff_matrix) # "xtabs" "table" - not a distance/pairwise comparisons matrix! it still has the same columns as the dataframe (just the selected ones)

What have I done wrong? Any suggestion on how to achieve this in a simple way? Thanks! Gabriella

I have this: head(ibd.coeff_df) # dataframe ID1 ID2 k0 k1 niter kinship 1 18SHK0006 18SHK0007 0.4717972 0.3759833 172 0.1701056

I coded this: ibd.coeff_matrix = xtabs(kinship ~ ID1 + ID2, data=ibd.coeff_df)

I got this: ibd.coeff_matrix ID1 ID2 kinship 1 18SHK0006 18SHK0007 0.1701056

I expected this:

    ID2

ID1 18SHK0007 18SHK0012 ... 18SHK0006 0.170105574 ....

0

There are 0 answers