2 more ways:
]k =: 'a';'b';'c';'d';'e'
+-+-+-+-+-+
|a|b|c|d|e|
+-+-+-+-+-+
n =: 7
]kk =: n $ <0
+-+-+-+-+-+-+-+
|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+
(1) Simple
k ,"0 1 kk NB. Columns directly
+-+-+-+-+-+-+-+-+
|a|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|b|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|c|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|d|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|e|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
k ,"0 1 (<"0 i.7) NB. Same value in each column
+-+-+-+-+-+-+-+-+
|a|0|1|2|3|4|5|6|
+-+-+-+-+-+-+-+-+
|b|0|1|2|3|4|5|6|
+-+-+-+-+-+-+-+-+
|c|0|1|2|3|4|5|6|
+-+-+-+-+-+-+-+-+
|d|0|1|2|3|4|5|6|
+-+-+-+-+-+-+-+-+
|e|0|1|2|3|4|5|6|
+-+-+-+-+-+-+-+-+
(2) Over-engineered :-)
anr =: 1 : '],($~(u,$))' NB. Add N Rows: result =: kk n anr k
]kk =: <0
+-+
|0|
+-+
|: kk n anr k
+-+-+-+-+-+-+-+-+
|a|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|b|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|c|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|d|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|e|0|0|0|0|0|0|0|
+-+-+-+-+-+-+-+-+
|: kk # anr k NB. Monads work too: Add #k rows
+-+-+-+-+-+-+
|a|0|0|0|0|0|
+-+-+-+-+-+-+
|b|0|0|0|0|0|
+-+-+-+-+-+-+
|c|0|0|0|0|0|
+-+-+-+-+-+-+
|d|0|0|0|0|0|
+-+-+-+-+-+-+
|e|0|0|0|0|0|
+-+-+-+-+-+-+
]kk =: 0
0
]k =: 5 [EMAIL PROTECTED] 100
46 55 79 52 54
|: kk 7 anr k
46 0 0 0 0 0 0 0
55 0 0 0 0 0 0 0
79 0 0 0 0 0 0 0
52 0 0 0 0 0 0 0
54 0 0 0 0 0 0 0
'hocus pocus' 3 anr 'abracadabra'
abracadabra
hocus pocus
hocus pocus
hocus pocus
]kk =: 1 2 3
1 2 3
|: kk 7 anr k
46 1 3 2 1 3 2 1
55 2 1 3 2 1 3 2
79 3 2 1 3 2 1 3
52 1 3 2 1 3 2 1
54 2 1 3 2 1 3 2
On 04/05/2008 05:00, [EMAIL PROTECTED] wrote:
------------------------------
Message: 4
Date: Sat, 03 May 2008 13:37:24 -600
From: "PackRat" <[EMAIL PROTECTED]>
...
Related to the "NEW-merge-to-MASTER" question I had a while back, I'm
trying to write a generalized way of adding a variable number of rows
(columns eventually, via tranposing):
j=. <array of boxed cells, where each row is a literal cell followed
by numeric cells>
n=. (1{($j))-1 NB. n is the number of data columns AFTER the first
k=. 'a';'b';'c';'d';'e' NB. "toy" example
kk=. n$<0
...
What I'm looking for is some expression (or explicit verb definition)
that will automatically create "n" rows of boxed zeros connected to
list "k" of boxed data. (Additionally, perhaps a similar expression
could add "n" vectors of zeros to an existing numeric vector.) It
would seem that something like that ought to be possible, right?
Thanks in advance!
Harvey
------------------------------
Message: 5
Date: Sat, 3 May 2008 22:55:48 +0200
From: "R.E. Boss" <[EMAIL PROTECTED]>
...
With n=5, is this what you are looking for?
k,5#,:kk
...
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm