Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

APL - quickest way?
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


Report this thread to moderator Post Follow-up to this message
Old Post
AAsk
03-13-08 12:59 PM


Re: APL - quickest way?
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
Gosi
03-13-08 12:59 PM


Re: APL - quickest way?
APL the quickest way?

i.e. APL not J

Report this thread to moderator Post Follow-up to this message
Old Post
AAsk
03-13-08 12:59 PM


Re: APL - quickest way?
On 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Phil Last
03-14-08 08:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

APL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:54 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.