Check if object is array (that it is a vector with a dim attribute) and that the object has dimnames and that dimnames are named.

is.named.array(obj)

is_named_array_(obj)

is_number_vector_(obj)

is_dimnames_(obj)

dimnames_match(a1, a2)

Arguments

obj

Some R object.

a1, a2

Arrays with named dimnames.

Author

Søren Højsgaard, sorenh@math.aau.dk

Examples

is.named.array( HairEyeColor )
#> [1] TRUE
is.named.array( matrix(1:4, nrow=2) )
#> [1] FALSE
is_named_array_( HairEyeColor )
#> [1] TRUE
is_named_array_( matrix(1:4, nrow=2) )
#> [1] FALSE
is_number_vector_(1:4)
#> [1] TRUE
is_number_vector_(list(1:4))
#> [1] FALSE

ar1 = tabNew(c("a", "b"), levels=c(2, 3))
ar2 = tabNew(c("c", "a"), levels=c(2, 2))
ar1
#>    b
#> a   1 2 3
#>   1 1 1 1
#>   2 1 1 1
ar2
#>    a
#> c   1 2
#>   1 1 1
#>   2 1 1
## dimension a has levels a1,a2 in both ar1 and ar2.
# Hence we have a match.
dimnames_match(ar1, ar2)
#> [1] TRUE

ar1 = tabNew(c("a", "b"), levels=c(2, 3))
ar2 = tabNew(c("c", "a"), levels=c(2, 3))
ar1
#>    b
#> a   1 2 3
#>   1 1 1 1
#>   2 1 1 1
ar2
#>    a
#> c   1 2 3
#>   1 1 1 1
#>   2 1 1 1
## dimension a has levels a1,a2 in ar1 and levels a1,a2,a3 in ar2.
# Hence we do not have a match.
dimnames_match(ar1, ar2)
#> [1] FALSE

ar2 = tabNew(c("c", "a"), levels=list(c=c("c1", "c2"), a=c("a2", "a1")))
ar2
#>     a
#> c    a2 a1
#>   c1  1  1
#>   c2  1  1
## dimension a has levels a1,a2 in ar1 and levels a2,a1 in ar2.
# Hence we do not have a match.
dimnames_match(ar1, ar2)
#> [1] FALSE