<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Stack columns based on regex selection in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17527#M15984</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;welcome, thanks.&amp;nbsp; Use an explicit data table whenever possible:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;dtstacked = dt &amp;lt;&amp;lt; Stack(&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; columns( icols ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Source Label Column( "Label" ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Stacked Data Column( "Data" )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dtstacked will reference the data table that results from dt&amp;lt;&amp;lt;stack.&amp;nbsp; Use the dtstacked variable to make sure commands go to that table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Mar 2016 16:48:17 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2016-03-18T16:48:17Z</dc:date>
    <item>
      <title>Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17523#M15980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am constantly stacking hundreds of columns which have common prefixes and end with a different number or suffix. &lt;/P&gt;&lt;P&gt;What I would like to do is write a script to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Find columns based on a regex pattern, e.g. "BLUE_CARS_*_\d{1,2}", "HOMES_(SINGLE|DOUBLE)_WIDE", etc.&lt;/LI&gt;&lt;LI&gt;Select those columns&lt;/LI&gt;&lt;LI&gt;Stack the columns (and place in a new datasheet)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the life of me, I can't find (or Google search properly for) how to use regex with column selection.&lt;/P&gt;&lt;P&gt;I considered selecting the columns by data type, but there are other columns present which share that data type, not to&lt;/P&gt;&lt;P&gt;mention I want something much more flexible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions or code snippets would be immensely appreciated, and thank you in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Mar 2016 00:31:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17523#M15980</guid>
      <dc:creator>tsandidge</dc:creator>
      <dc:date>2016-03-18T00:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17524#M15981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier; line-height: 1.5em;"&gt;dt = Open( "$sample_data/big class.jmp" );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;allCols = dt &amp;lt;&amp;lt; getcolumnnames;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;Show( allCols ); // these are names, not strings&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;acols = {}; // columns with "a" in their name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;icols = {}; // columns with "i" in their name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;n = N Items( allCols );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;For( k = 1, k &amp;lt;= n, k++,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; cname = allCols&lt;K&gt; &amp;lt;&amp;lt; getname; // these are strings, good for regex&lt;/K&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Show( cname );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; If( !Is Missing( Regex( cname, "a" ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Insert Into( acols, allCols&lt;K&gt; ) // keep the names&lt;/K&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; If( !Is Missing( Regex( cname, "i" ) ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Insert Into( icols, allCols&lt;K&gt; ) // keep the names&lt;/K&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;Show( acols, icols ); // {:name, :age} and {:height, :weight}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;dt &amp;lt;&amp;lt; Stack(&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; columns( icols ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Source Label Column( "Label" ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Stacked Data Column( "Data" )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11154_stack.PNG" style="width: 899px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/2844iDF560C8187504407/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11154_stack.PNG" alt="11154_stack.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Oct 2016 02:09:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17524#M15981</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-10-19T02:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17525#M15982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might have to turn off the translate checkbox at the top of the screen to see the JSL correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Mar 2016 14:21:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17525#M15982</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-03-18T14:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17526#M15983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great! That's exactly what I needed.&lt;/P&gt;&lt;P&gt;I'm still getting familiar with the jsl syntax and the need to 'show' everything.&lt;/P&gt;&lt;P&gt;And for the Regex() function, I couldn't find any documentation on using that outside of a regular column function, so that's handy it works the same way. This will prove useful in so many ways.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Related, how would I make sure I have the new table/window selected to use in the rest of a script?&lt;/P&gt;&lt;P&gt;Also, I definitely had to turn off the translation, because it was messing up the code.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Mar 2016 16:06:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17526#M15983</guid>
      <dc:creator>tsandidge</dc:creator>
      <dc:date>2016-03-18T16:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17527#M15984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;welcome, thanks.&amp;nbsp; Use an explicit data table whenever possible:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;dtstacked = dt &amp;lt;&amp;lt; Stack(&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; columns( icols ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Source Label Column( "Label" ),&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 8pt;"&gt;&amp;nbsp; Stacked Data Column( "Data" )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: 'courier new', courier;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dtstacked will reference the data table that results from dt&amp;lt;&amp;lt;stack.&amp;nbsp; Use the dtstacked variable to make sure commands go to that table.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Mar 2016 16:48:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17527#M15984</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-03-18T16:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17528#M15985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And yes, I left some show functions in the JSL because they are helpful debugging aids.&amp;nbsp; Take them out when you are done so the log isn't cluttered with old answers to old questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Craige&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Mar 2016 19:17:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17528#M15985</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-03-18T19:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17529#M15986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm encountering issues turning this code into a JMP add-in (with a button). The code works great when I run it from the script editor, but when I try to run it as an add-in, it gives the following complaint:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;CODE&gt;Send Expects Scriptable Object in access or evaluation of 'Send' , nc&lt;I&gt; &amp;lt;&amp;lt;&amp;nbsp; /*###*/get name/*###*/&lt;/I&gt;&lt;/CODE&gt;&lt;I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;For( i = 1, i &amp;lt;= N Items( nc ), i++,&amp;nbsp; cname = nc&lt;I&gt; &amp;lt;&amp;lt;&amp;nbsp; /*###*/get name/*###*/;&amp;nbsp; model = nc&lt;I&gt; &amp;lt;&amp;lt; get modeling type;&lt;/I&gt;&lt;/I&gt;&lt;/CODE&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I change the first line to read, &lt;CODE&gt;cname = dt &amp;lt;&amp;lt; get name(nc&lt;I&gt;);&lt;/I&gt;&lt;/CODE&gt;&lt;I&gt; it moves on to complain about the next line. &lt;BR /&gt;I then change this line to read, &lt;CODE&gt;model = dt &amp;lt;&amp;lt; get modeling type(nc&lt;I&gt;);&lt;/I&gt;&lt;/CODE&gt;&lt;I&gt; and it moves on down to a sort() function, changing the error: &lt;BR /&gt;&lt;CODE&gt;&lt;CODE&gt;Send Expects Scriptable Object in access or evaluation of 'Send' , transposed &amp;lt;&amp;lt;/*###*/sort( replace table, by( "Row 1" ), order( Descending ) ) /*###*/&lt;BR /&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;and the code reads&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;transposed = transposed &amp;lt;&amp;lt; /*###*/ sort(replace table, by("Row 1"), order(Descending))/*###*/;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE&gt;&lt;BR /&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;Any ideas about how I can resolve this as well as make it portable (work in both the editor and as an add-in without a problem)? My apologies for how unclear this may seem.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;(Wow, why is there no message preview button...).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 17:58:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17529#M15986</guid>
      <dc:creator>tsandidge</dc:creator>
      <dc:date>2016-03-28T17:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17530#M15987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;show( i, nc );&lt;/P&gt;&lt;P&gt;will show the current values of the two variables.&amp;nbsp; Slip that in after the "i++," increment in the loop.&amp;nbsp; nc *should* display as a list (in curly braces) of column names.&amp;nbsp; the &amp;lt;&amp;lt;getname message is intended for a column in this case.&amp;nbsp; The data table may also have a &amp;lt;&amp;lt;getname method, but that's probably not what you want, and the getname method probably ignores any argument you supply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the log after you run it with the show command and see what's wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scriptable Objects in JMP are objects that understand messages.&amp;nbsp; A variable could hold a matrix, list, or number, which are not scriptable objects, or the variable could hold a displaybox, data table, or column, which are scriptable objects.&amp;nbsp; There are lots of other types too, some scriptable, some not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My guess is the data table isn't explicitly chosen by the add-in, and the errors cascade from there.&amp;nbsp; You might need another show() before this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Craige&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 18:25:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17530#M15987</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-03-28T18:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Stack columns based on regex selection</title>
      <link>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17531#M15988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The show() and details about what was going on helped me see that we were actually telling it to use a column name, not the actual column–I suppose that makes sense since &amp;lt;code&amp;gt;nc = dt &amp;lt;&amp;lt; get column names;&amp;lt;/code&amp;gt; was used in the first place. So, instead of&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;cname = nc&lt;I&gt; &amp;lt;&amp;lt; get name;&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;we needed&lt;/P&gt;&lt;P&gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;cname = column(nc&lt;I&gt;) &amp;lt;&amp;lt; get name;&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;I guess by default &amp;lt;code&amp;gt;get column names()&amp;lt;/code&amp;gt; returns the strings, not a list of the columns. Ah, well, it's working as expected now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 18:40:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Stack-columns-based-on-regex-selection/m-p/17531#M15988</guid>
      <dc:creator>tsandidge</dc:creator>
      <dc:date>2016-03-28T18:40:54Z</dc:date>
    </item>
  </channel>
</rss>

