# create a symmetric matrix
kinship <- matrix(
c(
0.5, 0.1, 0.0,
0.1, 0.5, 0.2,
0.0, 0.2, 0.6
),
nrow = 3
)
# add names (best for tidy version)
colnames(kinship) <- paste0('pop', 1:3)
rownames(kinship) <- paste0('pop', 1:3)
# this returns tidy version
kinship_tidy <- tidy_kinship( kinship )
# test colnames
stopifnot( colnames( kinship_tidy ) == c('id1', 'id2', 'kinship') )
# test row number
stopifnot( nrow( kinship_tidy ) == 6 )
# inspect it
kinship_tidy
Run the code above in your browser using DataLab