First observe for 2 numbers,
6 ,&": 63
663
generalise it with rank operator to work on pairs of scalar number
(>{.aa) ,&:":"0 (>{:aa)
663
302
15
1717
119103
11814
1161
This is a character vector, to turn it back into number, it needs
(>{.aa) ".@,&:":"0 (>{:aa)
or
(>{.aa) ".@:,&:":"0 (>{:aa)
663 302 15 1717 119103 11814 1161
Чтв, 14 Июл 2011, PackRat писал(а):
> I wish to append the digits of two numbers to form a new number:
> 12 345 --> 12345
>
> I'm sure this is elementary, but I'm currently stumped. Here's some
> data (which in reality would have been read in from a CSV file and then
> transposed):
>
> aa=. 2 7 $ 6;30;1;17;119;118;116;63;2;5;17;103;14;1
>
> +--+--+-+--+---+---+---+
> |6 |30|1|17|119|118|116|
> +--+--+-+--+---+---+---+
> |63|2 |5|17|103|14 |1 |
> +--+--+-+--+---+---+---+
>
> Then I pulled out the numeric data pairs, converted them to literals,
> and appended them:
>
> b=. ( ": every 0{aa ) ,. ( ": every 1{aa )
>
> 6 63
> 30 2
> 1 5
> 17 17
> 119103
> 11814
> 1161
>
> Just for visual purposes here (NOT in J!), I substituted * for spaces,
> to show what's happening:
>
> 6**63*
> 30*2**
> 1**5**
> 17*17*
> 119103
> 11814*
> 1161**
>
> However, what I want to end up with is this, no spaces, different
> lengths:
>
> 663
> 302
> 15
> 1717
> 119103
> 11814
> 1161
>
> To attempt to do this, I did the following:
>
> spc=. ' ' E. every b
>
> 0 1 1 0 0 1
> 0 0 1 0 1 1
> 0 1 1 0 1 1
> 0 0 1 0 0 1
> 0 0 0 0 0 0
> 0 0 0 0 0 1
> 0 0 0 0 1 1
>
> keepmask=. (0 = spc)
>
> 1 0 0 1 1 0
> 1 1 0 1 0 0
> 1 0 0 1 0 0
> 1 1 0 1 1 0
> 1 1 1 1 1 1
> 1 1 1 1 1 0
> 1 1 1 1 0 0
>
> I thought that the following would accomplish what I wanted, but it
> does NOT:
>
> nospc=. keepmask # each b
>
> +-+-+-+-+-+-+
> |6| | |6|3| |
> +-+-+-+-+-+-+
> |3|0| |2| | |
> +-+-+-+-+-+-+
> |1| | |5| | |
> +-+-+-+-+-+-+
> |1|7| |1|7| |
> +-+-+-+-+-+-+
> |1|1|9|1|0|3|
> +-+-+-+-+-+-+
> |1|1|8|1|4| |
> +-+-+-+-+-+-+
> |1|1|6|1| | |
> +-+-+-+-+-+-+
>
> Essentially, this puts me right back where I started, without
> accomplishing anything. I thought it would be a very straightforward
> process to append the digits of two numbers--it's sort of the reverse
> of what was discussed here recently. The final step, of course, is to
> convert the new literal back into a number (but that part's easy!).
>
> I appreciate any help with this--thanks in advance!
>
> Harvey
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm