enve.df2dist.group {enveomics.R} | R Documentation |
Enveomics: Data Frame to Dist (Group)
Description
Transform a dataframe (or coercible object, like a table) into a dist object, where there are 1 or more distances between each pair of objects.
Usage
enve.df2dist.group(
x,
obj1.index = 1,
obj2.index = 2,
dist.index = 3,
summary = median,
empty.rm = TRUE
)
Arguments
x |
A dataframe (or coercible object) with at least three columns:
|
obj1.index |
Index of the column containing the ID of the object 1. |
obj2.index |
Index of the column containing the ID of the object 2. |
dist.index |
Index of the column containing the distance. |
summary |
Function summarizing the different distances between the two objects. |
empty.rm |
Remove rows with empty or |
Value
Returns a dist object.
Author(s)
Luis M. Rodriguez-R [aut, cre]
Examples
# A sparse matrix representation of distances as data frame.
# Note that some pairs are repeated.
dist.df <- data.frame(
query = c("A", "A", "A", "B", "C", "C", "B", "B", "B"),
subject = c("A", "B", "C", "B", "C", "B", "A", "C", "C"),
distance = c( 0, 0.1, 0.4, 0, 0, 0.4, 0.2, 0.2, 0.1)
)
dist <- enve.df2dist.group(dist.df)
print(dist)
# Use the mean of all repeated occurrences instead of the median.
dist <- enve.df2dist.group(dist.df, summary = mean)
# Simply use the first occurrence for any given pair.
dist <- enve.df2dist.group(dist.df, summary = function(x) head(x, n = 1))
[Package enveomics.R version 1.9.1 Index]