RE: [R] Generating list of vector coordinates

From: <Bill.Venables_at_csiro.au>
Date: Tue 29 Mar 2005 - 10:09:28 EST


> rev(expand.grid(k = 1:5, j = 1:4, i = 1:3))

   i j k
1 1 1 1
2 1 1 2
3 1 1 3
4 1 1 4
5 1 1 5

6 1 2 1
7 1 2 2
8 1 2 3

...

55 3 3 5
56 3 4 1
57 3 4 2
58 3 4 3
59 3 4 4
60 3 4 5
>

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Ronnen Levinson Sent: Tuesday, 29 March 2005 9:21 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Generating list of vector coordinates

   Hi.
   Can anyone suggest a simple way to obtain in R a list of vector

   coordinates of the following form? The code below is Mathematica.

     In[5]:=
     Flatten[Table[{i,j,k},{i,3},{j,4},{k,5}], 2]
     Out[5]=
     {{1,1,1},{1,1,2},{1,1,3},{1,1,4},{1,1,5},{1,2,1},{1,2,2},{1,2,3},{1
     ,2,4},{1,2,

     5},{1,3,1},{1,3,2},{1,3,3},{1,3,4},{1,3,5},{1,4,1},{1,4,2},{1,4,3},
     {1,4,

     4},{1,4,5},{2,1,1},{2,1,2},{2,1,3},{2,1,4},{2,1,5},{2,2,1},{2,2,2},
     {2,2,

     3},{2,2,4},{2,2,5},{2,3,1},{2,3,2},{2,3,3},{2,3,4},{2,3,5},{2,4,1},
     {2,4,

     2},{2,4,3},{2,4,4},{2,4,5},{3,1,1},{3,1,2},{3,1,3},{3,1,4},{3,1,5},
     {3,2,

     1},{3,2,2},{3,2,3},{3,2,4},{3,2,5},{3,3,1},{3,3,2},{3,3,3},{3,3,4},
     {3,3,
         5},{3,4,1},{3,4,2},{3,4,3},{3,4,4},{3,4,5}}

   I've been futzing with apply(), outer(), and so on but haven't found

   an elegant solution.
   Thanks,
   Ronnen.
   P.S. E-mailed CCs of posted replies appreciated.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Mar 29 10:18:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:56 EST