[R] change data into array

Suyan Tian stian at mail.rockefeller.edu
Tue Oct 28 19:59:15 CET 2008


Sorry to bother everyone again with one question about array.  I have  
one data set saved in this way

patient    time     x1      x2      response
1               1         1        8         1
1               2         2        7         1
2               1         3        6         1
2               2         4        5         1
3               1         5       4          2
3               2         6       3          2
4               1        7        2          2
4               2        8        1          2

I am wondering if there is any easy way to change the data into an  
array that 1st dimension is for variables (x1 and x2),  2nd is for  
patients (I would like to call it replicates), 3rd is for time  (2  
and 1), 4th is for response (2 and 1). The resulted array would look  
like as follows:

, , 1, 1

      [,1] [,2]
[1,]    1    3
[2,]    8   6

, , 2, 1

      [,1] [,2]
[1,]    2   4
[2,]    7   5

, , 1, 2

      [,1] [,2]
[1,]    5  7
[2,]   4   2

, , 2, 2

      [,1] [,2]
[1,]   6   8
[2,]   3   1


Thanks a lot,

Suyan



More information about the R-help mailing list