<?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 JSL script - How to create a column with repeating values? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/190651#M40944</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;despite looking into many discussions / the scripting index .., I could not get an answer, how to write a JSL script, that will take over the new column command enabling to enter sequence data with N times repetition of each value. I know how to do it manually - thanks to a reply from Mark B... in one of those discussions, but I struggle to write a script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;N_DOE= 10&lt;/P&gt;&lt;P&gt;N_XRF =4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;=&amp;gt; {1,1,1,1,2,2,2,2,3,3,3,3, ...10,10,10,10}&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//How may I get a column with repeating values

dt=current data table();

N_DOE=10; 
N_XRF=4;

seq = sequence(1,N_DOE,1,N_XRF);

dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal");

//dt:run &amp;lt;&amp;lt; set each value(seq,); // this works, but it is just"1" for all rows

dt:run &amp;lt;&amp;lt; set each value(i=1,i&amp;lt;N_DOE,i++, seq);

//dt:run &amp;lt;&amp;lt; set each value(for(i=1,i&amp;lt;N_DOE,i++, seq));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", values(repeat(seq));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", values(repeat(for(i=1,i&amp;lt;N_DOE,i++, seq))));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", for each row(for(i=1,i&amp;lt;N_DOE,i++, seq)));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", for each row(seq));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Apr 2019 15:45:57 GMT</pubDate>
    <dc:creator>PS_Ato</dc:creator>
    <dc:date>2019-04-01T15:45:57Z</dc:date>
    <item>
      <title>JSL script - How to create a column with repeating values?</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/190651#M40944</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;despite looking into many discussions / the scripting index .., I could not get an answer, how to write a JSL script, that will take over the new column command enabling to enter sequence data with N times repetition of each value. I know how to do it manually - thanks to a reply from Mark B... in one of those discussions, but I struggle to write a script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;N_DOE= 10&lt;/P&gt;&lt;P&gt;N_XRF =4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;=&amp;gt; {1,1,1,1,2,2,2,2,3,3,3,3, ...10,10,10,10}&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//How may I get a column with repeating values

dt=current data table();

N_DOE=10; 
N_XRF=4;

seq = sequence(1,N_DOE,1,N_XRF);

dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal");

//dt:run &amp;lt;&amp;lt; set each value(seq,); // this works, but it is just"1" for all rows

dt:run &amp;lt;&amp;lt; set each value(i=1,i&amp;lt;N_DOE,i++, seq);

//dt:run &amp;lt;&amp;lt; set each value(for(i=1,i&amp;lt;N_DOE,i++, seq));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", values(repeat(seq));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", values(repeat(for(i=1,i&amp;lt;N_DOE,i++, seq))));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", for each row(for(i=1,i&amp;lt;N_DOE,i++, seq)));

//dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", for each row(seq));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 15:45:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/190651#M40944</guid>
      <dc:creator>PS_Ato</dc:creator>
      <dc:date>2019-04-01T15:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script - How to create a column with repeating values?</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/190704#M40959</link>
      <description>&lt;P&gt;The Sequence() function really only works within a formula. Take a look at it in the Scripting Index&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Help==&amp;gt;Scripting Index.......Sequence&lt;/P&gt;
&lt;P&gt;Here is a working example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");

N_DOE=10; 
N_XRF=4;

dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal");

// Create the JSL required to set the format and then
// execute it
Eval( Parse(
	"dt:run &amp;lt;&amp;lt; set formula( sequence(1, " || char(N_DOE) ||
	", ince = 1, n = " || char(N_XRF) || "));"
		)
	);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Apr 2019 00:27:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/190704#M40959</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-04-02T00:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script - How to create a column with repeating values?</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/191393#M41061</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8938"&gt;@PS_Ato&lt;/a&gt;, Jim,&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp; has already provided a solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The JMP functions,&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt; Sequence()&lt;/STRONG&gt;&lt;/FONT&gt; and&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt; Count()&lt;/FONT&gt; &lt;/STRONG&gt;are very cool functions when working with a data table, since both functions rely on the &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Row()&lt;/STRONG&gt;&lt;/FONT&gt; of the current data table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There might be times when you want the sequence in just a matrix.&amp;nbsp; One method is the matrix function&amp;nbsp; &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Direct Product(amat, bmat)&lt;/STRONG&gt; &lt;/FONT&gt;.&amp;nbsp; The script below is similar to your original script; it creates &lt;STRONG&gt;seq&lt;/STRONG&gt; a vector of repeated values, then assigns them to the new column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is provided as an FYI.&amp;nbsp; If you have not used matrices or studied linear algebra, this would not be the first function that might pop into your mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
N_DOE=10; 
N_XRF=4;

New Table("Dummy", add rows(N_DOE * N_XRF));
dt=current data table();


seq = Transpose(Direct Product(Index(1,N_DOE),J(1,N_XRF,1)));
dt &amp;lt;&amp;lt; new column("Run", "numeric", "ordinal", values(seq));


/*  Log output
seq = Transpose(Direct Product(Index(1,N_DOE),J(1,N_XRF,1)));

[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]

*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 07:46:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-How-to-create-a-column-with-repeating-values/m-p/191393#M41061</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2019-04-05T07:46:58Z</dc:date>
    </item>
  </channel>
</rss>

