s-news
[Top] [All Lists]

Re: transforming 2D matrix to 4D array

To: "Liaw, Andy" <andy_liaw@merck.com>, "'Xao Ping'" <xao_ping@yahoo.com>, s-plus user list <s-news@lists.biostat.wustl.edu>
Subject: Re: transforming 2D matrix to 4D array
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Wed, 16 Feb 2005 22:00:56 -0500
If it is already sorted correctly, then it can be done even faster than
Andy suggested by just assigning the new dimensions.

> m <- matrix(1:16, 2, 8)
> m
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] 
[1,]    1    3    5    7    9   11   13   15
[2,]    2    4    6    8   10   12   14   16
> dim(m) <- c(2,2,2,2)
> m

, , 1, 1
     [,1] [,2] 
[1,]    1    3
[2,]    2    4

, , 2, 1
     [,1] [,2] 
[1,]    5    7
[2,]    6    8

, , 1, 2
     [,1] [,2] 
[1,]    9   11
[2,]   10   12

, , 2, 2
     [,1] [,2] 
[1,]   13   15
[2,]   14   16
> 

<Prev in Thread] Current Thread [Next in Thread>