The object b created in the question is a vector named R, not an array R.
an array
An array R is a vector R with size (or dimensions) and, possibly, the dimnames attribute. It is created as follows:
ar <- array(c(0, a), dimnames = list(c("index", "value"))); ar ## index value ## 0.0 1.9
named vector
To create a named vector with the specified names, rather than create an array, use setNames to overwrite any existing names:
v <- setNames(c(0, a), c("index", "value")); v
or use names<- as follows:
v <- c(0, a) names(v) <- c("index", "value")
or as mentioned in the comments, create b from unname(a) , not from a , to avoid unified names.
attributes
Note the ar attributes:
attributes(ar) ## List of 2 ## $ dim : int 2 ## $ dimnames:List of 1 ## ..$ : chr [1:2] "index" "value"
and attributes v :
attributes(v) ## $names ## [1] "index" "value"
source share