[Jprogramming] How to tell if all boxes in a row are empty?
bill lam
bbill.lam at gmail.com
Wed Jun 1 05:48:50 UTC 2016
step by step example.
] a=. a: (<1)} <"0 i. 3 5
+--+--+--+--+--+
|0 |1 |2 |3 |4 |
+--+--+--+--+--+
| | | | | |
+--+--+--+--+--+
|10|11|12|13|14|
+--+--+--+--+--+
(0=#) &> a NB.test for empty in each cell
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
*./ (0=#) &> a NB. closed but not what we wanted
0 0 0 0 0
*./"1 (0=#) &> a NB. this work with rank operator
0 1 0
*./ |: (0=#) &> a NB. transpose also work
0 1 0
The key is the adverb &> which open each cell, do something, then
assemble again. It also works if you have a more complicated
verb instead of tacit (0=#), eg
foo=: 3 : 0
if. #y do. 1 else. 0 end.
)
and then proceed with
foo &> a
Ср, 01 июн 2016, PR PackRat написал(а):
> I need to perform a certain action if an entire row in a transposed
> table (i.e., originally a column) has empty values, that is, all boxed
> data are the equivalent of a: or ''. The result should be a Boolean
> value--"true" meaning that the entire row has empty values. (A
> typical application would be old stock market data, where all of the
> "Open" values might be null or empty.)
>
> I don't know how to even begin writing such code (without a for/next
> loop to separately evaluate each box's value, a very non-J way of
> doing it). Please help. Thanks in advance!
>
>
> Harvey
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
More information about the Programming
mailing list