Skip to main content
19 events
when toggle format what by license comment
Aug 28, 2012 at 17:57 comment added alancalvitti @kguler, ... I'm trying to emulate this function using Thread: MapIfList[f_, x_] := If[Length[x] > 0, Map[f, x], f[x]]
Aug 28, 2012 at 17:56 comment added alancalvitti @kguler, that works on lists of dates but not singletons (Thread[Unevaluated@SelectInFrame[{2007, 1, 30}, m2], List, 1] --> {{}, {}, {}} ) . The purpose of this Thread construction is to selectively map on lists but also on singleton arguments
Aug 28, 2012 at 2:40 comment added kglr @alan, I am not sure if this answers the question in your comment: with m2 as above, Thread[Unevaluated@ SelectInFrame[{{2008, 2, 23}, DateList[{2009, 10, 14}][[;; 3]]}, m2], List, 1] gives {{{{2008, 2, 23}, 4, "y"}}, {{{2009, 10, 14}, 5, "z"}}}.
Aug 28, 2012 at 1:14 comment added alancalvitti @kguler, yes, only the 1st row or 1st column (part of the "frame") elements are changed from String to List as you show - the remaining elements can stay numbers or anything else. I describe this issue more in my own answer to the question here: mathematica.stackexchange.com/questions/9702/…
Aug 27, 2012 at 21:50 comment added kglr @alan, can you give the examples of M and Thread usage mentioned in your comment where Thread[...,{2}] works/does not work? Is M something like m2 = {{{2007, 1, 30}, 3, "x"}, {{2008, 2, 23}, 4, "y"}, {{2009, 10, 14}, 5, "z"}}?
Aug 27, 2012 at 20:33 comment added alancalvitti @kguler, can you extend this answer if the first column of M contains Lists, eg {2012,8,25} rather than Strings? I find that it works if the last argument to Thread is {2} to match a single such list, but doesn't match lists of lists, eg {{2012,8,25},{2012,8,27}} (assuming M contains those).
Aug 27, 2012 at 1:18 comment added kglr Thread evaluates the whole expression before threading. You need to use Unevaluated to prevent this behavior. So, Thread[Unevaluated@SelectInFrame[2, M], List, 1] gives {{2,3}} and Thread[Unevaluated@SelectInFrame[{2, 3}, M], List, 1] gives {{{2, 3}}, {{3, 4}}}.
Aug 26, 2012 at 18:59 comment added alancalvitti @kguler, I can't get the desired behavior with the following function: SelectInFrame[h_, data_] := Select[data, #[[1]] == h &]. Using the same M, Thread[SelectInFrame[2, M], List, 1] --> {{2}, {3}} (it should be {2,3}) and Thread[SelectInFrame[{2, 3}, M], List, 1] returns error: "Thread::tpos: Cannot thread over positions 1 through 1 in {}". ?
Aug 25, 2012 at 23:18 comment added kglr alan, btw just noticed that @Leonid's answer and comment already adresses this question.
Aug 25, 2012 at 23:06 comment added kglr @alancalvitti, in effect you want to change the behavior of the attribute Listable to thread over selected arguments? I would defer to Leonid/Rojo/... on whether this is possible/advisable:)
Aug 25, 2012 at 22:35 comment added alancalvitti Very nice. Is there any way to make Listable work with these options?
Aug 25, 2012 at 22:31 history edited kglr CC BY-SA 3.0
added 139 characters in body; added 4 characters in body
Aug 25, 2012 at 22:27 comment added Mr.Wizard I am mistaken, it does! Thread[f[M, {a, b, c}], List, {2}] (For some reason I didn't think that worked.)
Aug 25, 2012 at 22:25 comment added Mr.Wizard +1 because this is useful information and the question is not well defined, but I interpret that the solution should also handle f[M, {a, b, c}] and this, as written, does not.
Aug 25, 2012 at 22:22 history edited kglr CC BY-SA 3.0
added 79 characters in body; added 139 characters in body
Aug 25, 2012 at 22:22 history undeleted kglr
Aug 25, 2012 at 22:14 history deleted kglr
Aug 25, 2012 at 22:14 review Low quality posts
Aug 25, 2012 at 22:19
Aug 25, 2012 at 22:13 history answered kglr CC BY-SA 3.0