Well it seems to be in science anyway.
Data is often collected
Tag Treatment Measurement1 Measurement2 Measurement3
But it is more flexible to work with the data if it is in the form
Tag Treatment Measurement Value
Hence the requirement to reshape!
There is a package in R called reshape that defines the function melt
that does this.
Thanks for the answers, I'll add this to my study material
By the way Chris' answer doesn't work in its current form when the array
is boxed. Good exercise for me to see if I can work out why!
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Chris Burke
Sent: Thursday, 8 February 2007 15:43
To: Programming forum
Subject: Re: [Jprogramming] reshaping array
Why is this a common operation? Anyway:
a=. 100+i.4
b=. 21+i.5
c=. i.4 5
(>,{a;b),.,c
100 21 0
100 22 1
100 23 2
100 24 3
...
Sherlock, Ric wrote:
> Is there a built in mechanism for doing the following common
operation?
>
> How would I go about reshaping the following data from this
>
> ]tst=.(<'id') (<0;0)}(;/20+i.6),((;/100+i.4),.<"0 i.4 5)
> +---+--+--+--+--+--+
> |id |21|22|23|24|25|
> +---+--+--+--+--+--+
> |100|0 |1 |2 |3 |4 |
> +---+--+--+--+--+--+
> |101|5 |6 |7 |8 |9 |
> +---+--+--+--+--+--+
> |102|10|11|12|13|14|
> +---+--+--+--+--+--+
> |103|15|16|17|18|19|
> +---+--+--+--+--+--+
>
> To this?
>
> +---+---+---+
> |id |cat|val|
> +---+---+---+
> |100| 21| 0|
> +---+---+---+
> |100| 22| 1|
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm