And for purely numeric csv data, I would not use readcsv at all.  If I
wrote the files myself, I would use:

   ".;._2 fread

Or, if someone else wrote the file, I would use instead:
   0&".;._2@,&',';._2 fread

These will be much faster (and more compact) than readcsv.

Also, your 'a' is not exactly like data that you would get from
readcsv.  To make it the same, use
    ":@,L:0 a

But let's go the other direction and simplify it:
   A=: 0&".&> ":@,L:0 a

So, you have ordered dates in the first column of A:

   {."1 A
77247 77251 77252 77253 77254 77257

You want an index vector that spans those values:

   ({.,{:) {."1 A
77247 77257

   -~/\ ({.,{:) {."1 A
77247 10
In other words you want 10 values starting from 77247:
   (+i.)/ -~/\ ({.,{:) {."1 A
77247 77248 77249 77250 77251 77252 77253 77254 77255 77256

In other words, you have these days from your desired list:
   (e.~ [: (+i.)/ [: -~/\ ({.,{:)) {."1 A
1 0 0 0 1 1 1 1 0 0

except that is missing your end day from its selection list and we
will want to be manipulating A with the result

So...

allDays=: [: (+ i.@>:)/ [: -~/\ [: ({. , {:) {."1
   (((e. {."1)~) allDays) A
1 0 0 0 1 1 1 1 0 0 1

   ((],.[ #inv~ (e. {."1)~) allDays) A
77247 77247 1 2 3 4 5 6
77248     0 0 0 0 0 0 0
77249     0 0 0 0 0 0 0
77250     0 0 0 0 0 0 0
77251 77251 1 2 3 4 5 6
77252 77252 1 2 3 4 5 6
77253 77253 1 2 3 4 5 6
77254 77254 1 2 3 4 5 6
77255     0 0 0 0 0 0 0
77256     0 0 0 0 0 0 0
77257 77257 1 2 3 4 5 6

Though what you really want is:

padDays=: (],. [:}."1 [ #inv~ (e. {."1)~) allDays
   padDays A
77247 1 2 3 4 5 6
77248 0 0 0 0 0 0
...

FYI,

-- 
Raul


On Thu, Oct 13, 2011 at 11:46 PM, PackRat <[email protected]> wrote:
> Here's some faux stock market data for July 1-11, 2011:
>
>   a=. 77247;1;2;3;4;5;6
>   a=. a,.(77251;1;2;3;4;5;6)
>   a=. a,.(77252;1;2;3;4;5;6)
>   a=. a,.(77253;1;2;3;4;5;6)
>   a=. a,.(77254;1;2;3;4;5;6)
>   a=. a,.(77257;1;2;3;4;5;6)
>   a=. |: a
>
>   a
> +-----+-+-+-+-+-+-+
> |77247|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77251|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77252|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77253|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77254|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77257|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
>
> The above is how the data appears after reading it in from a CSV file.
>
> As you may note, there are missing dates due to market closures for
> weekends and holidays.  I'd like to insert zeroed data so that every
> daynum is accounted for.  Here's what I'd like the result to look like:
>
> +-----+-+-+-+-+-+-+
> |77247|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77248|0|0|0|0|0|0|
> +-----+-+-+-+-+-+-+
> |77249|0|0|0|0|0|0|
> +-----+-+-+-+-+-+-+
> |77250|0|0|0|0|0|0|
> +-----+-+-+-+-+-+-+
> |77251|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77252|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77253|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77254|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
> |77255|0|0|0|0|0|0|
> +-----+-+-+-+-+-+-+
> |77256|0|0|0|0|0|0|
> +-----+-+-+-+-+-+-+
> |77257|1|2|3|4|5|6|
> +-----+-+-+-+-+-+-+
>
> I'm stumped as to how to fill in the missing values.  Any assistance
> would be greatly appreciated!
>
>
> 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