In this case, you probably don't want to use boxes. A working model with rank for the test case is:
dates ,"1"1 _ hours The result should have shape 28 974 96 5 . */ 28 974 96 5 13090560 This is a lot of data, but I think it is doable. Then you just need a simple numbers->format verb to run rank 1 on your results. Marshall -----Original Message----- From: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] On Behalf Of Bill Harris Sent: Monday, December 27, 2010 5:50 PM To: Programming forum Subject: Re: [Jprogramming] Cartesian products On Mon, December 27, 2010 2:27 pm, Marshall Lochbaum wrote: > { is the primitive you want. Something like: > > { (<"1 ,/dates) ,&< (<"1 hours) > > should get you started. Maybe > > ((}:$dates),(#hours),5) $ , ;@> { (<"1 ,/dates) ,&< (<"1 hours) Thanks. That's very close. I don't want to split on days, so (((}:$dates)*(1,#hours)),5) $ , ;@> { (<"1 ,/dates) ,&< (<"1 hours) seems to do the trick. The real data has $ dates -> 28 974 3 and $ hours -> 96 2. I can find the shape of that, but I can't calculate the results without running out of memory. :-( I'll try a few things, but tips are welcome. > ? > > This works, although it uses boxes a lot. Another option which works > for the test case is valid if this is a true Cartesian product in > years, months, days, hours, and minutes: > >> { 2010 2009 2010 ; 1 ; 1 2 3 4 ; 0 ; 15 30 45 60 > > , i.e. (list of years);(list of months);(list of days);(list of > hours);(list of minutes) Nice suggestion, but I don't think it quite works here. Year month day triples are read from a spreadsheet and aren't guaranteed to be regular / common across all the sets. I could have used that idiom to create the hours - minutes set, though. Thanks, Marshall. Bill > Marshall > > -----Original Message----- > From: programming-boun...@jsoftware.com > [mailto:programming-boun...@jsoftware.com] On Behalf Of Bill Harris > Sent: Monday, December 27, 2010 5:07 PM > To: programming@jsoftware.com > Subject: [Jprogramming] Cartesian products > > I've been working in R too long, and my J is rusty. > > I'm trying to take what seems like the Cartesian product of two > arrays. In particular, I've got a list of lists of dates, and I want > to turn them into ISO timestamps with a consistent HMS appended to them. > > The dates list might look like > > dates =: 1 4 3 $ 2010 01 01 2010 01 02 2010 01 03 2010 01 04 dates =: > dates, 4 3 $ 2009 01 01 2009 01 02 2009 01 03 2009 01 04 dates =: > dates, 4 3 $ 2010 01 01 2010 01 02 2010 01 03 2010 01 04 > > That's 3 sets of data, each with 4 dates, and each date with 3 > components. (In general, each set of data could have a different > number of dates.) > > The complete hours list looks like > > hoursmins=: 24 (<95 0) } 24 60 #: 15 * >: i. 96 > > but a simple version for this example might only have 4 times: > > hours =: 4 2 $ 0 15 0 30 0 45 0 60 > > What I want looks roughly like > > 2010 01 01 00:15:00.00 > 2010 01 01 00:30:00.00 > 2010 01 01 00:45:00.00 > 2010 01 01 00:60:00.00 > 2010 01 02 00:00:00.00 > . > . > . > 2010 01 04 00:60:00.00 > > 2009 01 01 00:15:00.00 > . > . > . > > The last step needs the isotimestamp verb from dates, so I need to get > to lines of the form > > 2010 01 01 0 15 > 2010 01 01 0 30 > > and so forth. The rank of that result should be 3 16 5: 3 sets of 16 > date-time stamps, each with 5 components. > > I've tried lots of alternatives, including variants on catalog and on > Henry's JfC ,"_1 _ "_ _1, all to no avail. I suspect it's trivial; can > someone help? > > Thanks, > > Bill > > PS: I apologize if this comes through twice. I originally sent it > from the wrong email address, which I suspect will get it blocked. > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm