match_n_to_m: Force n to m matching on a set of pairs

Description Usage Arguments Details Examples

View source: R/match_n_to_m.R

Description

Force n to m matching on a set of pairs

Usage

1
match_n_to_m(x, y, w, n = 1, m = 1)

Arguments

x

a vector of identifiers for each x in each pair This vector should have a unique value for each element in x.

y

a vector of identifiers for each y in each pair This vector should have a unique value for each element in y.

w

a vector with weights for each pair. The algorithm will try to maximise the total weight of the selected pairs.

n

an integer. Each element of x can be linked to at most n elements of y.

m

an integer. Each element of y can be linked to at most m elements of y.

Details

The algorithm will try to select pairs in such a way each element of x is matched to at most n elements of y and that each element of y is matched at most m elements of x. It tries to select elements in such a way that the total weight w of the selected elements is maximised.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
d <- data.frame(x=c(1,1,1,2,2,3,3), y=c(1,2,3,4,5,6,7), w=1:7)
# One-to-one matching:
d[match_n_to_m(d$x, d$y, d$w), ]

# N-to-one matching:
d[match_n_to_m(d$x, d$y, d$w, n=999), ]

# One-to-m matching:
d[match_n_to_m(d$x, d$y, d$w, m=999), ]

# N-to-M matching, e.g. select all pairs
d[match_n_to_m(d$x, d$y, d$w, n=999, m=999), ]

reclin documentation built on Nov. 23, 2021, 9:09 a.m.