Ok... You left out your example data for 'filer', but you gave enough detail that I think I can see what you are trying to do.
That said, I think that I would split this up into two different routines: One routine would deal with unpacking the "rows" (or "inverted columns) from your data and amending the result. (And possibly either converting back to character or ensuring that both character and numeric arguments are supported or possibly not - for now, I'll follow the pattern from your example.) The other routine would deal with the numeric "rescaling". We could either have different routines here (one for each different kind of rescaling) or we could use a switch statement and pack them all together like you did. Either way works. This routine would be an argument for the other routine. (So the other routine would be an adverb.) In other words: NB. sample data NB. Date Open High Low Close Volume filer=:|:":each ".;._2]0 :0 '2020-03-06';126.70;128.33;124.52;127.73;8193300 '2020-03-09';120.16;122.41;117.28;117.81;10757500 '2020-03-10';122.78;124.88;115.76;124.77;11410700 '2020-03-11';121.01;122.58;116.38;117.97;8446500 '2020-03-12';109.65;109.80;102.28;102.81;12512700 ) hiloclose=: 0 0 1 1 1 0 amender=:{{ ndx=. I.x NB. index vector from bit vector update=. u 0&".@> x#y (<"0 update) ndx} y }} rescaler=:{{ select. pricetype=. x case. 1 do. y case. 2 do. 10 * %: y case. 3 do. 100 * 10 ^. y end. }} Example use: hiloclose 1&rescaler amender filer ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │126.7 │120.16 │122.78 │121.01 │109.65 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │128.33 │122.41 │124.88 │122.58 │109.8 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │124.52 │117.28 │115.76 │116.38 │102.28 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │127.73 │117.81 │124.77 │117.97 │102.81 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │8193300 │10757500 │11410700 │8446500 │12512700 │ └──────────┴──────────┴──────────┴──────────┴──────────┘ hiloclose 2&rescaler amender filer ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │126.7 │120.16 │122.78 │121.01 │109.65 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │113.283 │110.639 │111.75 │110.716 │104.785 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │111.589 │108.296 │107.592 │107.88 │101.134 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │113.018 │108.54 │111.7 │108.614 │101.395 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │8193300 │10757500 │11410700 │8446500 │12512700 │ └──────────┴──────────┴──────────┴──────────┴──────────┘ hiloclose 3&rescaler amender filer ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │126.7 │120.16 │122.78 │121.01 │109.65 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │210.833 │208.782 │209.649 │208.842 │204.06 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │209.524 │206.922 │206.356 │206.588 │200.979 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │210.629 │207.118 │209.611 │207.177 │201.204 │ ├──────────┼──────────┼──────────┼──────────┼──────────┤ │8193300 │10757500 │11410700 │8446500 │12512700 │ └──────────┴──────────┴──────────┴──────────┴──────────┘ Now... of course, you might actually want to avoid the amends that I assumed you wanted from your textual description. Or you might want other things to be different. So this is only an approximation of what you might do. Also, beware that copy and paste may replace some space characters with characters which look like spaces but which are not (and may eliminate some newline characters). Worst case you'll have to type the code in by hand. And, of course, rather than have the three different rescaling verbs be 1&rescaler 2&rescaler and 3&rescaler you might instead give each of them a significant name. Still... perhaps this would be useful to you. Take care, -- Raul On Sun, May 16, 2021 at 1:01 AM HH PackRat <hhpack...@gmail.com> wrote: > > Hello--I was out of the house for much of today, so I haven't been > able to respond until now. > > Thanks to all who responded with suggestions! Unfortunately, none of > them worked as is, probably because you're used to a different way of > approaching the problem and also because I probably should have > indicated a fake example to show what I was looking for. Here are the > final versions of the code to accomplish my goal--please don't gasp > over the fact that I could create such "horrendous" looking lines of J > code. They work, and that's all I care about (the 2 files at the > beginning are file r1 and file r2 derived from file r). I got the > ideas here and there from the code you submitted. The following lines > of code successfully accomplished my goal: > > filer1=. 1 0 0 0 # filer NB. dates > filer2=. 0 1 1 1 # filer NB. work with high/low/close data > > if. 1 = pricetype do. NB. arithmetic scale > price=. filer2 > elseif. 2 = pricetype do. NB. square-root scale > price=. < every 10&*%: ". > every filer2 NB. x10 > elseif. 3 = pricetype do. NB. logarithmic scale > price=. < every 100&*10&^. ". > every filer2 NB. x100 > end. NB. if > > Mike Day asked, "You’ve already had some helpful, constructive, > replies. All I’ve got to add is to wonder why you’re working with > boxed data if your data are as regular as your example suggests." > > I work with boxed data because that's the way J imports stock market data: > > Date Open High Low Close Volume > ┌──────────┬──────┬──────┬──────┬──────┬────────┐ > │2020-03-06│126.70│128.33│124.52│127.73│8193300 │ > ├──────────┼──────┼──────┼──────┼──────┼────────┤ > │2020-03-09│120.16│122.41│117.28│117.81│10757500│ > ├──────────┼──────┼──────┼──────┼──────┼────────┤ > │2020-03-10│122.78│124.88│115.76│124.77│11410700│ > ├──────────┼──────┼──────┼──────┼──────┼────────┤ > │2020-03-11│121.01│122.58│116.38│117.97│8446500 │ > ├──────────┼──────┼──────┼──────┼──────┼────────┤ > │2020-03-12│109.65│109.80│102.28│102.81│12512700│ > └──────────┴──────┴──────┴──────┴──────┴────────┘ > > There are 3 types of data: Date, OHLC (rationals w/decimal fractions), > V (integers only). (I realize that integers are a subset of > rationals, but Volume can never have decimal fractions, so I > considered it a third type of data for my purposes.) Sorry for the > appearance of the table (it's copy-and-paste data), but that's the > main problem with proportional fonts, which I have no control over. > (Or, more accurately, I'm not aware of any control over fonts that I > may have in Gmail.) The above table is the starting point for my J > program, which spends the remainder of the code manipulating the data > in various ways. (For the following, Open prices and Volume are > omitted.) In case you're interested, the following 3 tables show the > results for arithmetic ("normal") scaling, square-root scaling (x10), > and logarithmic scaling (x100) for IBM stock in the middle of the > March 2020 "crash": > > ┌──────────┬──────────┬──────────┬──────────┬──────────┐ > │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │128.33 │122.41 │124.88 │122.58 │109.80 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │124.52 │117.28 │115.76 │116.38 │102.28 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │127.73 │117.81 │124.77 │117.97 │102.81 │ > └──────────┴──────────┴──────────┴──────────┴──────────┘ > > ┌──────────┬──────────┬──────────┬──────────┬──────────┐ > │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │113.28 │110.64 │111.75 │110.72 │104.79 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │111.59 │108.30 │107.59 │107.88 │101.13 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │113.02 │108.54 │111.70 │108.61 │101.40 │ > └──────────┴──────────┴──────────┴──────────┴──────────┘ > > ┌──────────┬──────────┬──────────┬──────────┬──────────┐ > │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │210.83 │208.78 │209.65 │208.84 │204.06 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │209.52 │206.92 │206.36 │206.59 │200.98 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │210.63 │207.12 │209.61 │207.18 │201.20 │ > └──────────┴──────────┴──────────┴──────────┴──────────┘ > > And here are the same scalings for the Dow-Jones Industrial Average > (which has far higher prices): > > ┌──────────┬──────────┬──────────┬──────────┬──────────┐ > │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │25994.38 │24992.36 │25020.99 │24604.63 │22837.95 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │25226.61 │23706.07 │23690.34 │23328.32 │21154.45 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │25864.77 │23851.02 │25018.16 │23553.22 │21200.61 │ > └──────────┴──────────┴──────────┴──────────┴──────────┘ > > ┌──────────┬──────────┬──────────┬──────────┬──────────┐ > │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │1612.28 │1580.90 │1581.80 │1568.59 │1511.22 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │1588.29 │1539.68 │1539.17 │1527.36 │1454.46 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │1608.25 │1544.38 │1581.71 │1534.71 │1456.04 │ > └──────────┴──────────┴──────────┴──────────┴──────────┘ > > ┌──────────┬──────────┬──────────┬──────────┬──────────┐ > │2020-03-06│2020-03-09│2020-03-10│2020-03-11│2020-03-12│ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │441.49 │439.78 │439.83 │439.10 │435.87 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │440.19 │437.49 │437.46 │436.79 │432.54 │ > ├──────────┼──────────┼──────────┼──────────┼──────────┤ > │441.27 │437.75 │439.83 │437.21 │432.63 │ > └──────────┴──────────┴──────────┴──────────┴──────────┘ > > The program is a "ZigZag" (or "Hi-Lo") program to determine where > price highs and lows occur in a set of market data, giving the user 5 > different sets of options to instruct the program how to operate. The > end result of the program is NOT a chart with lines joining the highs > and lows as would be typical with a zigzag program (I currently know > nothing about creating market charts in J). Rather, the output of the > program is a list of dates, each followed by the letter "H" (for a > high on the date) or the letter "L" (for a low on the date) which can > then be combined together with other kinds of data to achieve various > purposes. > > Again, a big THANK YOU to everyone who suggested various solutions to > my query! I greatly appreciate you all! > > Harvey > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm