Learn R Programming

AnimalSequences (version 0.2.0)

find_most_similar_columns: Find Most Similar Columns in a Distance Matrix

Description

This function identifies the most similar columns for each column in a distance matrix. For each column, it finds the columns with the smallest distances (i.e., most similar) based on the given number of similar columns to retrieve.

Usage

find_most_similar_columns(distance_matrix, n_similar = 3)

Value

A list of character vectors. Each element of the list corresponds to a column in the distance matrix and contains the column names of the most similar columns.

Arguments

distance_matrix

A numeric matrix where the distance between columns is represented. The rows and columns should correspond to the same set of entities.

n_similar

An integer specifying the number of most similar columns to find for each column. Default is 3.

Examples

Run this code
# Create a sample distance matrix
distance_matrix <- matrix(c(0, 1, 2, 1, 0, 3, 2, 3, 0),
                          nrow = 3,
                          dimnames = list(NULL, c("A", "B", "C")))

# Find the 2 most similar columns for each column
find_most_similar_columns(distance_matrix, n_similar = 2)

Run the code above in your browser using DataLab