One of my primary uses for J is to explore tables of data (such as CSV
files).

J has some nice addons like jdb and jd that simplify working with tables.
Tables feel natural in kdb since a dictionary can be flipped into a table.

I implemented a start to native tables in MicroJ (
https://github.com/joebo/microj), which I think is a nice extension for
working with tabular data. This prototype implementation could also be
considered as a project for integration into J once community git is opened
up

You can try it out here:

http://bit.ly/1QmuhC2

I am interested in any feedback.

Here's a transcript of some test cases:

NB. table type
NB. tables - flipping dictionary into a table
(flip ('abc';'xyx');(i.3);(1+i.3)) -: 0 : 0
+---+---+
|abc|xyx|
|---+---|
|0  |1  |
|---+---|
|1  |2  |
|---+---|
|2  |3  |
+---+---+
)

NB. tables - subsetting a table
(2 {. flip ('abc';'xyx');(i.3);(1+i.3)) -: 0 : 0
+---+---+
|abc|xyx|
|---+---|
|0  |1  |
|---+---|
|1  |2  |
+---+---+
)

NB. tables - taking the last row of a table
(_1 {. flip ('abc';'xyx');(i.3);(1+i.3)) -: 0 : 0
+---+---+
|abc|xyx|
|---+---|
|2  |3  |
+---+---+
)

('abc' /: flip ('abc';'xyx');(2 1 3);(1+i.3)) -: 0 : 0
+---+---+
|abc|xyx|
|---+---|
|1  |2  |
|---+---|
|2  |1  |
|---+---|
|3  |3  |
+---+---+
)

NB. tables - sort by column name
('xyx' /: flip ('abc';'xyx');(2 1 3);(1+i.3)) -: 0 : 0
+---+---+
|abc|xyx|
|---+---|
|2  |1  |
|---+---|
|1  |2  |
|---+---|
|3  |3  |
+---+---+
)


NB. tables - select column
((<'abc') { flip ('abc';'xyz');(1,2);(2,3)) -: 0 : 0
+---+
|abc|
|---|
|1  |
|---|
|2  |
+---+
)

NB. tables - select column and row
(0 { (<'abc') { flip ('abc';'xyz');(1,2);(2,3)) -: 0 : 0
+---+
|abc|
|---|
|1  |
+---+
)

NB. tables - update a column
((flip (<'abc');(1,2));(flip (<'abc');(3,4))) -: 0 : 0
+---+
|abc|
|---|
|3  |
|---|
|4  |
+---+
)

NB. tables - add a column
((flip (<'abc');(1,2));(flip (<'xyz');(3,4))) -: 0 : 0
+---+---+
|abc|xyz|
|---+---|
|1  |3  |
|---+---|
|2  |4  |
+---+---+
)

NB. tables - add a calculated column
((flip ('a';'b');(1,2);(3,5));(<'c');'a + b') -: 0 : 0
+--+--+--+
|a |b |c |
|--+--+--|
|1 |3 |4 |
|--+--+--|
|2 |5 |7 |
+--+--+--+
)

NB. table - filter
('a > 1' { (flip ('a';'b');(i. 4);(5+i. 4))) -: 0 : 0
+----+----+
|a   |b   |
|----+----|
|2   |7   |
|----+----|
|3   |8   |
+----+----+
)

NB. table - filter and sort
('a' \: 'a > 1' { (flip ('a';'b');(i. 4);(5+i. 4))) -: 0 : 0
+----+----+
|a   |b   |
|----+----|
|3   |8   |
|----+----|
|2   |7   |
+----+----+
)

NB. behead a table with a single column
(+/ }. (flip (<'a');(i.10))) -: 45

NB. behead a table with multiple columns

(}. (flip ('a';'b');(i. 5);(100+ i.5))) -: 0 : 0
+---------+-------------------+
|0 1 2 3 4|100 101 102 103 104|
+---------+-------------------+
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to