This is regarding reading and working with data from files.
(if text garbled, view it in Courier New font)
1) Input file:
aaa bb cccc dd e
1111 22 33333 444 55555 6 7 8
2) Read input as an array of values.
data =: cut"1 'm' freads y NB. y is the fully qualified file name
data
+----+--+-----+---+-----+-+-+-+
|aaa |bb|cccc |dd |e | | | |
+----+--+-----+---+-----+-+-+-+
|1111|22|33333|444|55555|6|7|8|
+----+--+-----+---+-----+-+-+-+
3) Now, pad the matrix in a way similar to $ operator for each dimention.
So, end result should look like:
+----+--+-----+---+-----+----+----+-----+
|aaa |bb|cccc |dd |e | aaa| bb |cccc |
+----+--+-----+---+-----+----+----+-----+
|1111|22|33333|444|55555|6 |7 |8 |
+----+--+-----+---+-----+----+----+-----+
Here is where I am not clear what is happening....
Attempt 1:
row =: 0 { $ data
col =: 1 { $ data
NB. removes empty words
NB. --->>> something goes wrong here...
trim =: cut @: dltb @: , @: >
NB. expands the list to the right size
pad =: 4 : '(1,x)$trim y'
datax =:,. col pad"0 1 data NB. Creates the catalog
datax
+----+--+--------+------+---+--+------+--+
|aaa |bb|ccccdd |e |aaa|bb|ccccdd|e |
+----+--+--------+------+---+--+------+--+
|1111|22|33333444|555556|7 |8 |1111 |22|
+----+--+--------+------+---+--+------+--+
As visible in the output, the 'dd' got stuck to the 'cccc' reducing the
number of data points.
Similarly between the 3's & 4's and 5's & 6's.
Maybe this is a naive (and buggy!) way of working with data.
Any suggestions?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm