distances: Create Core Hunter distance data from matrix or file.

View source: R/data.R

distancesR Documentation

Create Core Hunter distance data from matrix or file.

Description

Specify either a symmetric distance matrix or the file from which to read the matrix. See https://www.corehunter.org for documentation and examples of the distance matrix file format used by Core Hunter.

Usage

distances(data, file)

Arguments

data

Symmetric distance matrix. Unique row and column headers are required, should be the same and are used as item ids. Can be a numeric matrix or a data frame. The data frame may optionally include a first column NAME used to assign names to some or all individuals. The remaining columns should be numeric.

file

File from which to read the distance matrix.

Value

Distance matrix data of class chdist with elements

data

Distance matrix (numeric matrix).

size

Number of individuals in the dataset.

ids

Unique item identifiers.

names

Item names. Names of individuals to which no explicit name has been assigned are equal to the unique ids.

java

Java version of the data object.

file

Normalized path of file from which data was read (if applicable).

Examples

# create from distance matrix
m <- matrix(runif(100), nrow = 10, ncol = 10)
diag(m) <- 0
# make symmetric
m[lower.tri(m)] <- t(m)[lower.tri(m)]
# set headers
rownames(m) <- colnames(m) <- paste("i", 1:10, sep = "-")

dist <- distances(m)

# read from file
dist.file <- system.file("extdata", "distances.csv", package = "corehunter")
dist <- distances(file = dist.file)


corehunter documentation built on Sept. 1, 2023, 5:07 p.m.