Code Comments
Programming Forum and web based access to our favorite programming groups.Imagine a nested array like this: ID IND1 V1 IND2 V2 IND3 V3 DATE 1 A 100 - - - - 2001-12-01 2 A 80 - - C 20 2001-12-01 3 B 70 C 5 D 10 2001-12-01 where - indicates a missing or unassigned value. 1. Quickest APL way to reformat it as follows? (replacing missing values by zero) ID IND V DATE 1 A 100 2001-12-01 1 B 0 2001-12-01 1 C 0 2001-12-01 1 D 0 2001-12-01 2 A 80 2001-12-01 2 B 0 2001-12-01 2 C 20 2001-12-01 2 D 0 2001-12-01 3 A 0 2001-12-01 3 B 70 2001-12-01 3 C 5 2001-12-01 3 D 10 2001-12-01 2. Quickest APL way to reformat it as follows? (lose rows with missing values) ID IND V DATE 1 A 100 2001-12-01 2 A 80 2001-12-01 2 C 20 2001-12-01 3 B 70 2001-12-01 3 C 5 2001-12-01 3 D 10 2001-12-01
Post Follow-up to this messageOn Mar 13, 10:44=A0am, AAsk <AA2e...@lycos.co.uk> wrote:
> Imagine a nested array like this:
>
> ID =A0 =A0 IND1 =A0 =A0V1 =A0 =A0IND2 =A0 =A0V2 =A0 =A0IND3 =A0 =A0V3 =A0 =[/color
]
=A0DATE
>
> 1 =A0 =A0 =A0 A =A0 =A0 =A0 100 =A0 =A0- =A0 =A0 - =A0 =A0 =A0 =A0- =A0 =
=A0 - =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 A =A0 =A0 =A0 =A080 =A0 =A0- =A0 =A0 - =A0 =A0 =A0 =A0C =A0 =[/color
]
=A020 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 B =A0 =A0 =A0 =A070 =A0 =A0C =A0 =A0 5 =A0 =A0 =A0 =A0D =A0 =[/color
]
=A010 =A0 =A0 2001-12-01
>
> where - indicates a missing or unassigned value.
>
> 1. Quickest APL way to reformat it as follows?
> =A0 =A0(replacing missing values by zero)
>
> ID =A0 =A0 IND =A0 =A0 =A0V =A0 =A0 =A0 DATE
>
> 1 =A0 =A0 =A0 A =A0 =A0 =A0 100 =A0 =A0 2001-12-01
> 1 =A0 =A0 =A0 B =A0 =A0 =A0 =A0 0 =A0 =A0 2001-12-01
> 1 =A0 =A0 =A0 C =A0 =A0 =A0 =A0 0 =A0 =A0 2001-12-01
> 1 =A0 =A0 =A0 D =A0 =A0 =A0 =A0 0 =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 A =A0 =A0 =A0 =A080 =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 B =A0 =A0 =A0 =A0 0 =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 C =A0 =A0 =A0 =A020 =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 D =A0 =A0 =A0 =A0 0 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 A =A0 =A0 =A0 =A0 0 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 B =A0 =A0 =A0 =A070 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 C =A0 =A0 =A0 =A0 5 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 D =A0 =A0 =A0 =A010 =A0 =A0 2001-12-01
>
> 2. Quickest APL way to reformat it as follows?
> =A0 =A0(lose rows with missing values)
>
> ID =A0 =A0 IND =A0 =A0 =A0V =A0 =A0 =A0 DATE
>
> 1 =A0 =A0 =A0 A =A0 =A0 =A0 100 =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 A =A0 =A0 =A0 =A080 =A0 =A0 2001-12-01
> 2 =A0 =A0 =A0 C =A0 =A0 =A0 =A020 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 B =A0 =A0 =A0 =A070 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 C =A0 =A0 =A0 =A0 5 =A0 =A0 2001-12-01
> 3 =A0 =A0 =A0 D =A0 =A0 =A0 =A010 =A0 =A0 2001-12-01
If you want to do it in J you could do it like this
require'misc'
a=3D: 0 : 0
ID IND1 V1 IND2 V2 IND3 V3 DATE
1 A 100 - - - - 2001-12-01
2 A 80 - - C 20 2001-12-01
3 B 70 C 5 D 10 2001-12-01
)
b=3D:chop a
c=3D:TAB chop each b
d=3D:>{.c
e=3D:>}.c
(d)=3D:|:e
m1=3D:ID,.' ',.IND1,.' ',.V1,.' ',.DATE
m2=3D:ID,.' ',.IND2,.' ',.V2,.' ',.DATE
m3=3D:ID,.' ',.IND3,.' ',.V3,.' ',.DATE
m1,m2,m3
Post Follow-up to this messageOn Mar 13, 10:44 am, AAsk <AA2e...@lycos.co.uk> wrote: > Imagine a nested array like this: > > ID IND1 V1 IND2 V2 IND3 V3 DATE > > 1 A 100 - - - - 2001-12-01 > 2 A 80 - - C 20 2001-12-01 > 3 B 70 C 5 D 10 2001-12-01 > > where - indicates a missing or unassigned value. > > 1. Quickest APL way to reformat it as follows? > (replacing missing values by zero) > > ID IND V DATE > > 1 A 100 2001-12-01 > 1 B 0 2001-12-01 > 1 C 0 2001-12-01 > 1 D 0 2001-12-01 > 2 A 80 2001-12-01 > 2 B 0 2001-12-01 > 2 C 20 2001-12-01 > 2 D 0 2001-12-01 > 3 A 0 2001-12-01 > 3 B 70 2001-12-01 > 3 C 5 2001-12-01 > 3 D 10 2001-12-01 > > 2. Quickest APL way to reformat it as follows? > (lose rows with missing values) > > ID IND V DATE > > 1 A 100 2001-12-01 > 2 A 80 2001-12-01 > 2 C 20 2001-12-01 > 3 B 70 2001-12-01 > 3 C 5 2001-12-01 > 3 D 10 2001-12-01 If you already have an apl array then those "missing" values are already filled with something! In Dyalog if the array is the result of some external process then "null" values are likely to have been prefilled with the system variable =E2=8E=95NULL. As I recall getting stuff in from SAS a couple of decades ago empty cells were just =E2=8A=82''. Either way you need to know. So let's say you have a function (Nulls) that, given the array, returns a conforming boolean array that tells you which they are. I could now present fifty trivial ways to do the actual merge (option 1) or compression (option 2) but which of them is quickest and in fact which of them is possible depends on which APL and is almost certainly going to be quicker than running our (Nulls) function anyway.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.