Learn R Programming

nbpMatching (version 1.5.6)

make.phantoms: Add Phantom Rows and Columns

Description

The make.phantoms function will take an \(N\)x\(N\) matrix and add \(NP\) phantom elements, thus creating a matrix with \(N+NP\)x\(N+NP\) dimensions.

Usage

make.phantoms(x, nphantoms, name = "phantom", maxval = Inf, ...)

Value

a matrix or data.frame object

Arguments

x

A matrix or data.frame object, with \(N\)x\(N\) dimensions.

nphantoms

An integer, providing the number of phantom elements to add.

name

A character string, indicating the name attribute for new elements. Defaults to "phantom".

maxval

An integer value, the default value to give the pairs of phantoms (indeces [N+1:N+NP, N+1:N+NP]), assumed to be a maximum distance. Defaults to Inf.

...

Additional arguments, not used at this time.

Author

Cole Beck

Details

This function is internal to the gendistance function, but may be useful in manufacturing personalized distance matrices. Phantoms are fake elements that perfectly match all elements. They can be used to discard a certain number of elements.

See Also

gendistance distancematrix

Examples

Run this code

# 5x5 distance matrix
dist.mat <- matrix(c(0,5,10,15,20,5,0,15,25,35,10,15,0,25,40,15,25,25,0,15,20,35,40,15,0), nrow=5)
# add one phantom element
dm.ph <- make.phantoms(dist.mat, 1)
# create distancematrix object
distancematrix(dm.ph)
# add three phantoms
make.phantoms(dist.mat, 3)

Run the code above in your browser using DataLab