Well.., I don't know if you're even reading this, but... here's an
approach for #2.
I decided that since all numeric arrays are so much nicer to work
with, that I should use those from the start. Fixing up #1 to use the
same approach is left as an exercise for the reader:
B1=: _ {.@".every fixcsv 0 :0-.'-'
1952-05-22,261.78,264.02,261.54,263.33,1360000
1952-05-23,263.33,264.59,262.54,263.27,1150000
1952-05-24,263.27,263.47,262.84,263.23,300000
1952-05-25,0,0,0,0,0
1952-05-26,263.23,264.87,262.62,264.22,940000
1952-05-27,264.22,265.17,262.82,263.92,1040000
1952-05-28,263.92,264.54,262.25,262.78,1130000
1952-05-29,262.78,263.51,261.62,262.94,1100000
1952-05-30,0,0,0,0,0
1952-05-31,0 0 0 0 0
1952-06-01,0,0,0,0,0
1952-06-02,262.94,264.61,261.48,262.31,1190000
1952-06-03,262.31,262.82,260.83,262.09,940000
1952-06-04,262.09,264.20,261.91,263.67,1200000
1952-06-05,263.77,266.80,263.77,266.29,1410000
1952-06-06,266.29,268.95,266.21,268.03,1520000
1952-06-07,0,0,0,0,0
1952-06-08,0,0,0,0,0
1952-06-09,268.03,269.92,267.67,269.15,1270000
1952-06-10,269.15,269.15,266.76,267.67,1220000
1952-06-11,267.67,268.52,266.33,267.93,1190000
)
value_inertia=:verb define
data=. }."1 y
dates=. {."1 y
data_ndx=. >./\(i.@# * *)5{"1 y
dates,.data_ndx{data
)
To see the result, I recommend:
10 7j2 7j2 7j2 7j2 12j2 ": x:value_inertia B1
(Note also that there are performance advantages in using numeric
arrays over boxed arrays, which become measurable when the data sets
are large enough.)
To delete every feb 29th from your data set, if it's represented in
this format, you could use
nofeb29=: verb define
y#~0229~:10000|{."1 y
)
Thanks,
--
Raul
On Mon, Mar 30, 2020 at 9:33 PM HH PackRat <[email protected]> wrote:
>
> On to function #2 that I need (see how-to #1 for background) ....
>
> Given data set B below, moving from first to last, if the CLOSE value
> (column 4) is zero, replace the zeros in columns 1 to 5 with the
> preceding day's data (columns 1 to 5). Note that multiple zero rows
> will therefore have the same values for columns 1 to 5. The final
> resulting data set should have no zero values in columns 1 to 4.
> (It's possible, due to vendor glitches, that volume in column 5 may
> have a value of zero--ignore that.) Please don't overlook it, but I
> have another question at the end of this message.
>
> DATA SET B:
>
> 1952-05-22,261.78,264.02,261.54,263.33,1360000
> 1952-05-23,263.33,264.59,262.54,263.27,1150000
> 1952-05-24,263.27,263.47,262.84,263.23,300000
> 1952-05-25,0,0,0,0,0
> 1952-05-26,263.23,264.87,262.62,264.22,940000
> 1952-05-27,264.22,265.17,262.82,263.92,1040000
> 1952-05-28,263.92,264.54,262.25,262.78,1130000
> 1952-05-29,262.78,263.51,261.62,262.94,1100000
> 1952-05-30,0,0,0,0,0
> 1952-05-31,0 0 0 0 0
> 1952-06-01,0,0,0,0,0
> 1952-06-02,262.94,264.61,261.48,262.31,1190000
> 1952-06-03,262.31,262.82,260.83,262.09,940000
> 1952-06-04,262.09,264.20,261.91,263.67,1200000
> 1952-06-05,263.77,266.80,263.77,266.29,1410000
> 1952-06-06,266.29,268.95,266.21,268.03,1520000
> 1952-06-07,0,0,0,0,0
> 1952-06-08,0,0,0,0,0
> 1952-06-09,268.03,269.92,267.67,269.15,1270000
> 1952-06-10,269.15,269.15,266.76,267.67,1220000
> 1952-06-11,267.67,268.52,266.33,267.93,1190000
>
> Additional how-to question: if I wanted to delete every February 29
> leap day (date and data) from an entire set of calendar day data (my
> Dow Industrials data goes back to 1885) in order to have consistent
> 365-day years, how would I accomplish that in J?
>
> Again, thanks in advance for any and all help!
>
> 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