Thanks Chris,
That does the trick if not being as "nifty" as using catalog.
Thanks too to Raul although I'm yet to explore your suggestion in
detail.
Ric

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Chris Burke
Sent: Thursday, 8 February 2007 22:42
To: Programming forum
Subject: Re: [Jprogramming] reshaping array

Sherlock, Ric wrote:
> I'm probably not being clear about what I'm trying to do (then again 
> maybe I'm just not getting what you're trying to tell me!). I was only

> using 2 arguments for catalog because the left argument of melt is 
> supposed to describe how many "static" columns there are. Maybe a more

> "realistic" test array will help. In the array below the first two 
> columns are set i.e. treatment doesn't vary within Tag (129 had the 
> high treatment and only the high treatment). In another dataset there 
> might be three static columns say Tag, Gender, Trt.
>    tst2
> +---+----+-------+-------+-------+-------+
> |Tag|Trt |Wgt1   |Wgt2   |Wgt3   |Height |
> +---+----+-------+-------+-------+-------+
> |129|high|5.15114|5.8615 |8.51623|16.3878|
> +---+----+-------+-------+-------+-------+
> |125|low |5.51031|6.92476|9.12955|15.6384|
> +---+----+-------+-------+-------+-------+
> |109|high|3.10655|4.51398|8.51873|14.7903|
> +---+----+-------+-------+-------+-------+
> |100|high|3.25242|5.14918|8.44444|15.5832|
> +---+----+-------+-------+-------+-------+
> |108|low |3.89146|5.94608|7.79733|13.1512|
> +---+----+-------+-------+-------+-------+ 
> 
> What I want is
> +---+----+---------+-------+
> |Tag|Trt |Variable |Value  |
> +---+----+---------+-------+
> |129|high|Wgt1     |5.15114|
> +---+----+---------+-------+
> |129|high|Wgt2     |5.8615 |
> +---+----+---------+-------+

Got it. It is probably easiest just to pick out the labels and data, and
then reshape the labels to match the data, e.g.

meltdown=: 3 : 0
1 meltdown y
:
cls=. x }. {. y
rws=. }. x {."1 y
dat=. , x }."1 }. y
lbls=. (x{.{.y),;:'variable value'
lbls,((#cls)#rws),.(($dat)$cls),.dat
)

   T=: <;._1 ;._2 (0 : 0)
|Tag|Trt |Wgt1   |Wgt2   |Wgt3   |Height
|129|high|5.15114|5.8615 |8.51623|16.3878
|125|low |5.51031|6.92476|9.12955|15.6384
|109|high|3.10655|4.51398|8.51873|14.7903
|100|high|3.25242|5.14918|8.44444|15.5832
|108|low |3.89146|5.94608|7.79733|13.1512
)

   2 meltdown T
+---+----+--------+-------+
|Tag|Trt |variable|value  |
+---+----+--------+-------+
|129|high|Wgt1    |5.15114|
+---+----+--------+-------+
|129|high|Wgt2    |5.8615 |
+---+----+--------+-------+
|129|high|Wgt3    |8.51623|
+---+----+--------+-------+
|129|high|Height  |16.3878|
+---+----+--------+-------+
|125|low |Wgt1    |5.51031|
+---+----+--------+-------+
...

Again, the earlier problem you had was that the catalog was being done
on two arguments, one of which had boxed items and the other not. To fix
this, you would have to box each item of the second argument, and then
raze each item of the result, something like the following. But, it is
probably easiest to work as above.

   a=. <"1 <&> i.3 2
   b=. <&>i. 4
   ;&>,{a;<<each b
+-+-+-+
|0|1|0|
+-+-+-+
|0|1|1|
+-+-+-+
|0|1|2|
+-+-+-+
...
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to