This function allows the user to transform a distance matrix into a tidy_dist_mat matrix with information about the rows and columns in the tidyverse grouping style.

tidy_dist_mat(dist_mat, rownames_df = NULL, colnames_df = NULL)

Arguments

dist_mat

distance matrix

rownames_df

data.frame with row identifying information

colnames_df

data.frame with column identifying information

Value

tidy_dist_mat object

Examples

# data creation inner_data <- data.frame(x = rnorm(3), y = rnorm(3)) my_dist_mat <- as.matrix(dist(inner_data)) rownames_df <- data.frame(id = 1:3) colnames_df <- data.frame(id = c(1,2,1), id2 = c("f", "f", "s")) my_tidy_dm <- tidy_dist_mat(my_dist_mat, rownames_df, colnames_df) # visualizing the structure print(my_tidy_dm)
#> id #> id | 1 2 1 #> id2 | f f s #> - + ------- ------- ------- #> 1 | 0 1.48802 4.48924 #> 2 | 1.48802 0 5.26036 #> 3 | 4.48924 5.26036 0
# accessing structure rownames(my_tidy_dm)
#> id #> 1 1 #> 2 2 #> 3 3
colnames(my_tidy_dm)
#> id id2 #> 1 1 f #> 2 2 f #> 3 1 s
# updating structure rownames(my_tidy_dm) <- colnames_df my_tidy_dm
#> id id2 #> id | 1 2 1 #> id2 | f f s #> - - + ------- ------- ------- #> 1 f | 0 1.48802 4.48924 #> 2 f | 1.48802 0 5.26036 #> 1 s | 4.48924 5.26036 0