# 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))
Run the code above in your browser using DataLab