distancematrix: Distance matrix

Description Usage Arguments Details Value Author(s) See Also Examples

Description

The distancematrix function is used to reformat the input distance matrix into the format required by the nonbipartite matching Fortran code. The original matrix should have dimensions NxN, where N is the total number of elements to be matched. The matrix may be created in R and input into the distancematrix function. Alternately, the matrix may be read in from a CSV file, i.e. a text file where distances in a given row are delimited by commas. If a list element is given, it should have a data.frame element named "dist", preferably generated by the gendistance function.

Usage

1

Arguments

x

A matrix, data.frame, list or filename. This should be an NxN distance matrix for the N elements to be matched. The values in the diagonal are ignored because an element cannot be matched to itself. Using zeros in the diagonal is preferable, although other values are acceptable provided they are not so large that they distort the scaling of the other values.

...

Additional arguments, potentially used when reading in a filename and passed into read.csv.

Details

Value

distancematrix S4 object

Author(s)

Cole Beck

See Also

nonbimatch gendistance

Examples

1
2
3
4
5
6
7
8
9
plainmatrix<-as.matrix(dist(sample(1:25, 8, replace=TRUE)))
diag(plainmatrix) <- 99999  # setting diagonal to an infinite distance for
                           # pedagogical reasons (the diagonal may be left
                           # as zero)
mdm<-distancematrix(plainmatrix)
df <- data.frame(id=LETTERS[1:25], val1=rnorm(25), val2=rnorm(25))
df[sample(seq_len(nrow(df)), ceiling(nrow(df)*0.1)), 2] <- NA
df.dist <- gendistance(df, idcol=1, ndiscard=2)
mdm2 <- distancematrix(df.dist)

nbpMatching documentation built on May 29, 2017, 7:22 p.m.