Hi Harvey,
Sounds like the data given might be quite a simplification from the
reality, but let's start with that for now.

The following will subtract 12 from the boxed row of numbers in the
example. It assumes that the numeric values are numeric and not text.

dat=: '|'&splitstring;._2 -.&' ' noun define

aa | aa | aa | aa | aa

22 | 53 | 32 | 28 | 36

cc | cc | cc | cc | cc

)


load 'csv'  NB. just to get the makenum verb which converts numeric text
representations to numbers.

subtractFromNumericRow=: dyad define

newrow=. (-&12)&.> x { y

y=. newrow x}y

)

1 subtractFromNumericRow makenum dat

+--+--+--+--+--+

|aa|aa|aa|aa|aa|

+--+--+--+--+--+

|10|41|20|16|24|

+--+--+--+--+--+

|cc|cc|cc|cc|cc|

+--+--+--+--+--+


If the boxes contain a textual representation of numbers then the following
will work (but will leave numbers in the boxes)


subtractFromTextRow=: dyad define

newrow=. (12 -~ 0&".)&.> x { y

y=. newrow x}y

)


1 subtractFromTextRow dat

+--+--+--+--+--+

|aa|aa|aa|aa|aa|

+--+--+--+--+--+

|10|41|20|16|24|

+--+--+--+--+--+

|cc|cc|cc|cc|cc|

+--+--+--+--+--+


If you need to leave the numbers as text, then that is possible too, but
I'll leave that for now.

You could pass the constant to be subtracted as part of the x argument if
needed.



On Tue, Feb 23, 2021 at 10:01 PM HH PackRat <hhpack...@gmail.com> wrote:

> Hello again!
>
> I've run into another "stumper" (for me, at least).  True amending
> (according to the Vocabulary) does not work for boxed data, and the
> examples under "AmendingBoxedStructures" do not seem to be the kind of
> solution I'm looking for.
>
> What I'm trying to do is something that any human can rather easily
> do, but which I'm finding very challenging to program in J.  Below is
> a brief example of my issue with row E.  There are many rows above E
> and many rows below E.  (Sorry for the "A", but it was the closest
> that I could get to a similarly sized inverted "V".)  All of the rows
> can actually have hundreds or thousands of column values, rather than
> just the 5 column values illustrated here.  The row number for row E
> is known, as would be the number of boxed values in that row (there
> may be empty column values at the end of rows).  E's kind of row is
> repeated ever so often in the actual table I'm working with, but the
> number of values could vary somewhat from one of these rows to another
> (that is, it is NOT a constant value, but that probably makes no
> difference whatsoever for the solution of this problem--I just want to
> alert you that you cannot count on a fixed value for all row lengths
> in terms of quantity--some rows may have empty values at the end).
> Just an assumption caution: the table contains *both* numeric and
> literal data, NOT numeric data only.
>
>     A
>     |
> | aa | aa | aa | aa | aa |
> | 22 | 53 | 32 | 28 | 36 |   <---  row E
> | cc | cc | cc | cc | cc |
>     |
>     V
>
> Here's the problem: I want to subtract a constant value (say, 12) from
> each of the boxed values, so that row E will look like this:
>
> | 10 | 41 | 20 | 16 | 24 |
>
> The same principle would apply to all other similar rows, only each
> such row would have a different constant to subtract from all of the
> boxed values in the row.
>
> If each of these rows existed by themselves, I know how to do what I
> want.  However, I cannot figure out how to do it in the middle of a
> table of boxed values, where the data comes from external sources and
> where the lengths of rows can vary.  (The data in row E is
> astronomical data which is not strictly regular due to elliptical
> orbits rather than circular orbits, which is what leads to variations
> in speed.)
>
> The program I have written so far is what I thought was the more
> difficult part, and I thought the constant subtraction from values
> would be the easy part.  However, it has proved to be the opposite
> because I'm stumped by this.
>
> I appreciate any help that you can give (I'm always learning new stuff
> in J!).  The only thing I ask is that you please use EXPLICIT code and
> *not* tacit code.  Thanks in advance!
>
> 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

Reply via email to