Last data update: 2014.03.03

R: Consistency test between the column names of two matrices
checkNamesR Documentation

Consistency test between the column names of two matrices

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

checkNames(X1, X2, X1.name = "X1", X2.name = "X2")

Arguments

X1

a matrix containing column names.

X2

a matrix containing the same number of columns.

X1.name

,

X2.name

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

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

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DiceKriging)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DiceKriging/checkNames.Rd_%03d_medium.png", width=480, height=480)
> ### Name: checkNames
> ### Title: Consistency test between the column names of two matrices
> ### Aliases: checkNames
> ### Keywords: models
> 
> ### ** Examples
> 
> X1 <- matrix(1, 2, 3)
> X2 <- matrix(1:6, 2, 3)
> 
> colnames(X1) <- c("x1", "x2", "x3")
> checkNames(X1, X2)
     x1 x2 x3
[1,]  1  3  5
[2,]  2  4  6
Warning message:
In checkNames(X1, X2) : X2 not named: X2's variables are inherited from X1
> # 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)
     x1 x2 x3
[1,]  3  1  5
[2,]  4  2  6
> # returns the matrix X2, but with permuted columns
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>