tags:

views:

52

answers:

1

This is my first time using a 3 dimensional array and I am having problems naming the third dimension.

ReplicateData <- array(0,c(240,500,5),dimnames=list(NULL, NULL, c("Returns","Replicates","Asset Class")))

I am getting the error "Length of dimnames not equal to array extent" This seems like it should be a simple issue but I can't find an explicit example in the help docs or online.

+4  A: 

The third dimension of your array is of extent 5, but the vector of names for that dimension is of length three.

Jonathan Chang
Thanks. I was thinking that the name length should match the number of dimensions.
ProbablePattern
Well, that's something you can have, too;something we call "named dimnames".The table() function actually is an important example using them: > with(airquality, table(OzHi=Ozone > 80, Month, useNA="ifany")) Month OzHi 5 6 7 8 9 FALSE 25 9 20 19 27 TRUE 1 0 6 7 2 <NA> 5 21 5 5 1 You'd manually use something like tab. <- array(1:15, dim=c(3,5), dimnames= list(OzHi = c("FALSE", "TRUE", NA), Month = c("5", "6", "7", "8", "9")))to get the "same" [why on earth, can't I get "markdown" to work?]
Martin Mächler