It seems you may be running code, and checking resuts and perhaps not noticing errors being printed to your console ?
You have two kinds of issues, one is a simply R syntax issue, of missing comma, the other might be considered an issue of the arithmetic of the array creation.
First the easy one. I see in your latest examples where you use array() there is no comma between the dim = and the dimmnames = , therefore R must try to understand dimnames = as though it were part of dim= and not something seperate. Therefore this will fix some of your issue.
The second problem you seem to have is the arithmetic of your dimensions being apparently confused.
Lets consider the first of your two latest examples.
vector1 <- c(4,2,1,3,5,7)
vector2 <- c(22,34,76,88,98,65,76,44,33)
column.names <- c("COL1", "COL2", "COL3" )
row.names <- c("ROW1", "ROW2", "ROW3" , "ROW4")
matrix.names <- c(
"Matrix1", "Matrix2")
result <- array(c(vector1, vector2),dim = c(4,3,1),
dimnames = list(row.names, column.names, matrix.names))
print(result)
See that I added the required comma.
Now however we have a descriptive error.
length of 'dimnames' [3] not equal to array extent
lets think about what your commands amount to
length(c(vector1,vector2))
[1] 15
So there are 15 numbers to place inside an array of whatever dimensions...
column.names <- c("COL1", "COL2", "COL3" )
row.names <- c("ROW1", "ROW2", "ROW3" , "ROW4")
so we are going to arrange 15 numbers in some multiple of a 3x4 i.e. 12 number containing grid. ...
Now, this might be possible although confusing, given that you can technically mismatch the array content with the array dimensions, and have your content truncated or auto replicated to fill the space.
simple examples:
> array(c(1,2),dim=c(2,2))
[,1] [,2]
[1,] 1 1
[2,] 2 2
> array(1:5,dim=c(2,2))
[,1] [,2]
[1,] 1 3
[2,] 2 4
ok, but its a bit confusing, and for a handcrafted example like you have, seems possibly just a mistake. for example why even define vector1 and vector2 in two uneven sized parts, what meaning does that have ? anyway.
The critical can not compute issue is seen when you get to the final array() call and the dim does not match up with you dimnames. i.e. drop your dimnames param and the code will work. but if you want your dimnames there, which include Matrix1 and Matrix2 as names, then you must reflect that dimension length within dim with c(3,4,2), rather than the c(3,4,1) you have provided.
Hope this helps.