get_2ndbest: Get 2nd-smallest distance for each individual

View source: R/get_2ndbest.R

get_2ndbestR Documentation

Get 2nd-smallest distance for each individual

Description

For each individual represented in a distance matrix, find the 2nd-smallest entry (with NAs for individuals present in only the rows or only the columns).

Usage

get_2ndbest(d, dimension = c("row", "column"), get_min = TRUE)

Arguments

d

A distance matrix

dimension

Whether to get the 2nd-best by row or by column

get_min

If TRUE, get the 2nd-minimum; if FALSE, get the 2nd-maximum

Value

A vector with all distinct individuals, with the 2nd-smallest (or largest) value by row or column. We include all individuals so that the results are aligned with the results of get_self().

See Also

get_self(), get_best(), which_2ndbest(), get_nonself()

Examples

# align rows in the provided dataset, lineup2ex
aligned <- align_matrix_rows(lineup2ex$gastroc, lineup2ex$islet)
# find correlated columns
selected_genes <- (corr_betw_matrices(aligned[[1]], aligned[[2]], "paired") > 0.75)
# calculate correlation between rows
similarity <- corr_betw_matrices(t(lineup2ex$gastroc[,selected_genes]),
                                 t(lineup2ex$islet[,selected_genes]), "all")
# second-biggest value by row
secbest_byrow <- get_2ndbest(similarity, get_min=FALSE)

# second-biggest value by column
secbest_bycol <- get_2ndbest(similarity, get_min=FALSE, dimension="column")


kbroman/lineup2 documentation built on May 16, 2023, 12:18 p.m.