我如何 manipulate/extract 来自以下 table 的信息
How can I manipulate/extract info from the following table in J
]data=:_3 ]\ 'Jack';23;178;'Rick';27;181;'Alice';41;178;'Mitch';31;184;'Paul';32;179
┌─────┬──┬───┐
│Jack │23│178│
├─────┼──┼───┤
│Rick │27│181│
├─────┼──┼───┤
│Alice│41│178│
├─────┼──┼───┤
│Mitch│31│184│
├─────┼──┼───┤
│Paul │32│179│
└─────┴──┴───┘
第一个字段是姓名,第二个是年龄,第三个是身高厘米。
如果您搜索 [j] table you'll find this question,您的 [j] table you'll find this question 可以说是重复的,但很容易想象它的答案似乎不适用于您的数据,因此我修改了以下答案:
NB. Select names
0 {"1 data
+----+----+-----+-----+----+
|Jack|Rick|Alice|Mitch|Paul|
+----+----+-----+-----+----+
NB. test if name contains a 'k'
+/"1 'k' e.~ 0 {::"1 data
1 1 0 0 0
NB. select rows where the name contains a 'k'
(+/"1 'k' e.~ 0 {::"1 data) # data
+----+--+---+
|Jack|23|178|
+----+--+---+
|Rick|27|181|
+----+--+---+
(#~ [: +/"1 'k' e.~ 0&{::"1) data
+----+--+---+
|Jack|23|178|
+----+--+---+
|Rick|27|181|
+----+--+---+
NB. select names where height > 180
> 0{"1 (#~ 180 < 2&{::"1) data
Rick
Mitch
NB. get average age and height
(+/%#) 1 2 pick"1 data
30.8 180
NB. add a row
is =: 4 : 'data =: data, (<x),y'
years =: 1 : '<u'
cm =: 1 : '<u'
'Rebecca' is 24 years, 176 cm
... omitted ...
'Gregory' is 37 years, 182 cm
... omitted ...
load 'inverted'
,.&.> ifa data
+-------+--+---+
|Jack |23|178|
|Rick |27|181|
|Alice |41|178|
|Mitch |31|184|
|Paul |32|179|
|Rebecca|24|176|
|Gregory|37|182|
+-------+--+---+
最后一点来自 Inverted Tables,它有一些优点,可能最不重要的是它们回声不那么吵。
]data=:_3 ]\ 'Jack';23;178;'Rick';27;181;'Alice';41;178;'Mitch';31;184;'Paul';32;179
┌─────┬──┬───┐
│Jack │23│178│
├─────┼──┼───┤
│Rick │27│181│
├─────┼──┼───┤
│Alice│41│178│
├─────┼──┼───┤
│Mitch│31│184│
├─────┼──┼───┤
│Paul │32│179│
└─────┴──┴───┘
第一个字段是姓名,第二个是年龄,第三个是身高厘米。
如果您搜索 [j] table you'll find this question,您的 [j] table you'll find this question 可以说是重复的,但很容易想象它的答案似乎不适用于您的数据,因此我修改了以下答案:
NB. Select names
0 {"1 data
+----+----+-----+-----+----+
|Jack|Rick|Alice|Mitch|Paul|
+----+----+-----+-----+----+
NB. test if name contains a 'k'
+/"1 'k' e.~ 0 {::"1 data
1 1 0 0 0
NB. select rows where the name contains a 'k'
(+/"1 'k' e.~ 0 {::"1 data) # data
+----+--+---+
|Jack|23|178|
+----+--+---+
|Rick|27|181|
+----+--+---+
(#~ [: +/"1 'k' e.~ 0&{::"1) data
+----+--+---+
|Jack|23|178|
+----+--+---+
|Rick|27|181|
+----+--+---+
NB. select names where height > 180
> 0{"1 (#~ 180 < 2&{::"1) data
Rick
Mitch
NB. get average age and height
(+/%#) 1 2 pick"1 data
30.8 180
NB. add a row
is =: 4 : 'data =: data, (<x),y'
years =: 1 : '<u'
cm =: 1 : '<u'
'Rebecca' is 24 years, 176 cm
... omitted ...
'Gregory' is 37 years, 182 cm
... omitted ...
load 'inverted'
,.&.> ifa data
+-------+--+---+
|Jack |23|178|
|Rick |27|181|
|Alice |41|178|
|Mitch |31|184|
|Paul |32|179|
|Rebecca|24|176|
|Gregory|37|182|
+-------+--+---+
最后一点来自 Inverted Tables,它有一些优点,可能最不重要的是它们回声不那么吵。