checkNames: Consistency test between the column names of two matrices

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

View source: R/checkNames.R

Description

Tests if the names of a second matrix are equal to a given matrix up to a permutation, and permute its columns accordingly. When the second one has no column names, the names of the first one are used in the same order.

Usage

1
2
checkNames(X1, X2, X1.name = "X1", X2.name = "X2")
checkNamesList(X1, l2, X1.name = "X1", l2.name = "l2")

Arguments

X1

a matrix containing column names.

X2

a matrix containing the same number of columns.

l2

a list with length ncol(X1).

X1.name

,

X2.name

optional names for the matrix X1 and X2 theirselves (useful for error messages).

l2.name

optional names for l2.

Details

If X2 does not contain variable names, then the names of X1 are used in the same order, and X2 is returned with these names. Otherwise, if the column names of X1 and X2 are equal up to a permutation, the column of X2 are permuted according to the order of X1' names.

Value

The matrix X2, with columns possibly permuted. See details.

Author(s)

O. Roustant

See Also

predict,km-method, simulate,km-method

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
X1 <- matrix(1, 2, 3)
X2 <- matrix(1:6, 2, 3)

colnames(X1) <- c("x1", "x2", "x3")
checkNames(X1, X2)
# attributes the same names for X2, and returns X2

colnames(X2) <- c("x1", "x2", "x5")
## Not run: checkNames(X1, X2)
# returns an error since the names of X1 and X2 are different

colnames(X2) <- c("x2", "x1", "x3")
checkNames(X1, X2)
# returns the matrix X2, but with permuted columns

l2 <- list(x3 = 1, x2 = c(2, 3), x1 = -6)
checkNamesList(X1, l2)

DiceKriging documentation built on Feb. 24, 2021, 1:07 a.m.