[R] Naming rows/columns in a 3 dimensional array/dataframe

Marc Schwartz marc_schwartz at comcast.net
Tue Jul 31 22:35:23 CEST 2007


On Tue, 2007-07-31 at 19:03 +0100, Garavito,Fabian wrote:
> Can I assign names to rows/columns in a i x k x j matrix / dataframe?

You can use an array:

ARR <- array(1:18, c(3, 3, 3), 
             dimnames = list(LETTERS[1:3], LETTERS[4:6], LETTERS[7:9]))

> ARR
, , G

  D E F
A 1 4 7
B 2 5 8
C 3 6 9

, , H

   D  E  F
A 10 13 16
B 11 14 17
C 12 15 18

, , I

  D E F
A 1 4 7
B 2 5 8
C 3 6 9


> ARR["B", "E", "H"]
[1] 14


See ?array

By definition, matrices and dataframes are two dimensional, though you
can have a list containing N of them.

HTH,

Marc Schwartz



More information about the R-help mailing list