Terence -
I'm not clear on exactly what you're trying to do here and the information
you
supply seems inconsistent, i.e. your specification of "age" as "i.2" seems
incorrect as there are three age categories.
Also, as an aside, many of your expressions have ")" at the end, sometimes
multiple closing parens: these are always unnecessary in J as far as I can
see
given its right-to-left evaluation default.
Anyway, I hope the following is illuminating.
Devon
'age spec astig tear'=: i.&.>3 2 2 2 NB. Specify category indexes
age;spec;astig;tear
+-----+---+---+---+
|0 1 2|0 1|0 1|0 1|
+-----+---+---+---+
NB. Look at just first two combined orthogonally:
age ,&.> / spec
+---+---+
|0 0|0 1|
+---+---+
|1 0|1 1|
+---+---+
|2 0|2 1|
+---+---+
NB. Simply extend this idea to combine all four:
$r4a=: age ,&.> / spec ,&.>/ astig ,&.>/ tear
3 2 2 2
(<0 0 0 0){r4a
+-------+
|0 0 0 0|
+-------+
NB. But why make this array when each element is the same
NB. as its index? E.G.
]ix=. <?$r4a
+-------+
|1 0 0 1|
+-------+
ix{r4a
+-------+
|1 0 0 1|
+-------+
NB. You could form the 4-D array of the words instead:
asatdesc=.
('young';'pre-presbyopic';'presbyopic');('myope';'hypermetrope');('no';'yes');<'reduced';'normal'
NB. Same orthogonal combination as above but applied to single,
NB. four-part vector:
$r4d=. >(,&.>/)&.>/asatdesc,&.>&.>' ' NB. space at end to separate words
3 2 2 2
(<1 0 0 1){r4d
+-------------------------------+
|pre-presbyopic myope no normal |
+-------------------------------+
NB. But a 4-D array seems unnecessarily complicated.
]somecombo=. <;._2 'presbyopic myope yes normal '
+----------+-----+---+------+
|presbyopic|myope|yes|normal|
+----------+-----+---+------+
NB. Look up this combination:
]someix=. asatdesc i.&> <"0 somecombo
2 0 1 1
NB. or use the index to extract it:
someix{&>asatdesc
+----------+-----+---+------+
|presbyopic|myope|yes|normal|
+----------+-----+---+------+
NB. As for the last question:
]age_tbl =: (0;'young'),(1;'pre-presbyopic'),:2;'presbyopic'
+-+--------------+
|0|young |
+-+--------------+
|1|pre-presbyopic|
+-+--------------+
|2|presbyopic |
+-+--------------+
NB. Note the final ",:" to initialize as table
NB. Again, the numbers seem unnecessary as they are the same
NB. as the index.
On 6/11/07, Terrence Brannon <[EMAIL PROTECTED]> wrote:
Ok, how would I form the cartesian cross-product of these 4 vectors:
age =: i. 2 NB. young, pre-presbyopic, presbyopic
spec =: i. 1 NB. myope, hypermetrope
astig =: i. 1 NB. no, yes
tear =: i. 1 NB. reduced, normal
I presume the resulting cross product will be a rank-4 array. Call it r4a
...
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm