if (require(gurobi)) {
## Generate small example
m <- 3 # number of classes
n <- 10 # number of statistical units
p <- 5 # number of variables
mu <- matrix(rnorm(p*m),p,m) # mean vectors
sigma <- 0.1
x <- array(as.vector(mu) + rnorm(p*m*n,sigma), c(p,m,n))
## Match all feature vectors
result <- match.2x(x)
## Display results
result$cost # objective value = assignment cost
result$sigma # solution permutations
xmatched <- array(dim=dim(x))
## Matched feature vectors
for (i in 1:n)
xmatched[,,i] <- x[,result$sigma[,i],i]
}
Run the code above in your browser using DataLab