converting array to character matrix
Posted: Mon Feb 09, 2015 4:30 pm
Veteran apl guy...not too much apl2...stuck on something like this..
given an nx2 array of scalars (in this case characters), i simply want to form a single character matrix where the strings are aligned in columns..something akin to:
∇q∇
∇ z←q
[1] z←⍉2 4⍴'one' 'two' 'three' 'four' 'green' 'red' 'blue' 'yellow'
[2] z←(↑z[;1]),(((1↑⍴z),10)⍴''),↑z[;2]
∇
q
one green
two red
three blue
four yellow
i suspect there's some combination of APL2 constructs to get this done easily, but i haven't hit upon it. The example only contains 2 columns, but ideally i'd like to generalize it for n,m arrays.
I realize that ⍴↑z is 4 2 6 and i can dispense with the padded space by catinating along the second dimension (at the cost of not necessarily one space between the columns, but that's no prob), but that too isn't a general solution.
thanks for any help (just noticed that 'z' is not outputting on the screen correctly...think of z as two left justified excel columns)
given an nx2 array of scalars (in this case characters), i simply want to form a single character matrix where the strings are aligned in columns..something akin to:
∇q∇
∇ z←q
[1] z←⍉2 4⍴'one' 'two' 'three' 'four' 'green' 'red' 'blue' 'yellow'
[2] z←(↑z[;1]),(((1↑⍴z),10)⍴''),↑z[;2]
∇
q
one green
two red
three blue
four yellow
i suspect there's some combination of APL2 constructs to get this done easily, but i haven't hit upon it. The example only contains 2 columns, but ideally i'd like to generalize it for n,m arrays.
I realize that ⍴↑z is 4 2 6 and i can dispense with the padded space by catinating along the second dimension (at the cost of not necessarily one space between the columns, but that's no prob), but that too isn't a general solution.
thanks for any help (just noticed that 'z' is not outputting on the screen correctly...think of z as two left justified excel columns)