{ is the primitive you want. Something like: { (<"1 ,/dates) ,&< (<"1 hours)
should get you started. Maybe ((}:$dates),(#hours),5) $ , ;@> { (<"1 ,/dates) ,&< (<"1 hours) ? 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) 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