Skip to content

Array dimnames

4 messages · dave mitchell, Domenico Vistocco, Tony Plate

#
dave mitchell wrote:
Denoting with array3d the array and with matrix2d the data matrix:

colnames(array3d)=colnames(array3d)

Otherwise, using dimnames:
dimnames(array3d)=list(NULL,colnames(array3d),NULL)

You can operate using the "[" operator, that is:
array3d[,"region",] to extract the region columns from each dimension.

You obtain the same effect using the column number, i.e.
array3d[,2,]

domenico
#
Sorry, there were mistakes in variable names... (I realized only after 
pressed the send button)
Domenico Vistocco wrote:
colnames(array3d)=colnames(matrix2d)
dimnames(array3d)=list(NULL,colnames(matrix2d),NULL)
1 day later
#
I can't quite understand what you're having difficulty with (is it 
constructing the array, or coping with the different 'matrices' having 
different column names, or something else?)

However, your sample data looks like it has a mixture of factor (region) 
and numeric data (Qty), so you're probably storing it in a data frame. 
AFAIK, there is no 3d object in R that can store mixed-type data like a 
data frame can.  An array object in R has to have the same data type for 
every column etc.

-- Tony Plate
dave mitchell wrote: