<?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 How to use Column index (instead of Column name) in a formula. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74217#M35787</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to do this in a for loop:&lt;/P&gt;&lt;P&gt;In current table, I have 14&amp;nbsp;Columns. Column #3~#14 were named as "Step 1" to "Step 12".&lt;/P&gt;&lt;P&gt;In the for loop, I want to create Column #15 (named as "Delta Step i" for i = 2, i &amp;lt;=12, i++), which is calculated with formula (Col(4) -Col(2)). Then Column#3 was deleted. The same formula will be reused in the next iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two problems here,&lt;/P&gt;&lt;P&gt;1) my formula doesn't work as there is no value in Column#15 of the output table;&lt;/P&gt;&lt;P&gt;2)I am worried that once column3 is detected, the values in Column15 (actually Column 14, after Column 3 is deleted) will be gone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my script.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i=2,i&amp;lt;=15,i++,
	DeltaStep = "Delta Step "||Char(i);	
	New Column(DeltaStep)&amp;lt;&amp;lt;formula(Column(4) - Column(3));
	Column(3)&amp;lt;&amp;lt;delete columns
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried this, but not working, either.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i=2,i&amp;lt;=12,i++,
	DeltaStep = "Delta Step "||Char(i);
	Pre = Column(3) &amp;lt;&amp;lt; getname;
	Pst = Column(4) &amp;lt;&amp;lt; getname;
	New Column(DeltaStep)&amp;lt;&amp;lt;formula(:Pst - :Pre);
	Column(3)&amp;lt;&amp;lt;delete columns
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Sep 2018 16:54:48 GMT</pubDate>
    <dc:creator>Zihao</dc:creator>
    <dc:date>2018-09-19T16:54:48Z</dc:date>
    <item>
      <title>How to use Column index (instead of Column name) in a formula.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74217#M35787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to do this in a for loop:&lt;/P&gt;&lt;P&gt;In current table, I have 14&amp;nbsp;Columns. Column #3~#14 were named as "Step 1" to "Step 12".&lt;/P&gt;&lt;P&gt;In the for loop, I want to create Column #15 (named as "Delta Step i" for i = 2, i &amp;lt;=12, i++), which is calculated with formula (Col(4) -Col(2)). Then Column#3 was deleted. The same formula will be reused in the next iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Two problems here,&lt;/P&gt;&lt;P&gt;1) my formula doesn't work as there is no value in Column#15 of the output table;&lt;/P&gt;&lt;P&gt;2)I am worried that once column3 is detected, the values in Column15 (actually Column 14, after Column 3 is deleted) will be gone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my script.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i=2,i&amp;lt;=15,i++,
	DeltaStep = "Delta Step "||Char(i);	
	New Column(DeltaStep)&amp;lt;&amp;lt;formula(Column(4) - Column(3));
	Column(3)&amp;lt;&amp;lt;delete columns
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried this, but not working, either.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i=2,i&amp;lt;=12,i++,
	DeltaStep = "Delta Step "||Char(i);
	Pre = Column(3) &amp;lt;&amp;lt; getname;
	Pst = Column(4) &amp;lt;&amp;lt; getname;
	New Column(DeltaStep)&amp;lt;&amp;lt;formula(:Pst - :Pre);
	Column(3)&amp;lt;&amp;lt;delete columns
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 16:54:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74217#M35787</guid>
      <dc:creator>Zihao</dc:creator>
      <dc:date>2018-09-19T16:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Column index (instead of Column name) in a formula.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74240#M35797</link>
      <description>&lt;P&gt;I think I found why I am not doing this correctly...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first script in my post, I should add [] after Column(3)...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zihao&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 17:37:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74240#M35797</guid>
      <dc:creator>Zihao</dc:creator>
      <dc:date>2018-09-19T17:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Column index (instead of Column name) in a formula.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74249#M35798</link>
      <description>&lt;P&gt;I am also wrong for the "delete columns" expr.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached the correct script here, please let me know if any better way to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i=2,i&amp;lt;=12,i++,
	DeltaStep = "Delta Step "||Char(i);
	New Column(DeltaStep,formula(Column(4)[] - Column(3)[]));
	Column(3) &amp;lt;&amp;lt; Set Selected;
	dt &amp;lt;&amp;lt; Delete Columns
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 17:45:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74249#M35798</guid>
      <dc:creator>Zihao</dc:creator>
      <dc:date>2018-09-19T17:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Column index (instead of Column name) in a formula.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74284#M35801</link>
      <description>&lt;P&gt;Good catch! People often forget that Column(#) or Column("name")&amp;nbsp; need the empty brackets ( [] )&amp;nbsp; or the As Column() wrapper for row-wise calculations. I like to think of the reference as a pointer to the column header and attributes and the ref[] exposes the vector or list of values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding delete columns, it is a table message.&amp;nbsp; You could have alo used the JSL below without selecting the column beforehand.&lt;/P&gt;&lt;PRE&gt;dt &amp;lt;&amp;lt; Delete Columns( 3 );&lt;/PRE&gt;&lt;P&gt;Another common mistake is trying to delete a column that is used as an argument for another column formula.&amp;nbsp; Suppose Col 4 uses a formula that references Col 3. You must remove the dependent formula in Col 4, then you can delete Col 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is another reason for using &amp;lt;&amp;lt; Set Each Value(expression) vs. Formula (expression) for most cases, then the new columns are not locked, and dependencies do not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 19:09:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-use-Column-index-instead-of-Column-name-in-a-formula/m-p/74284#M35801</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2018-09-19T19:09:05Z</dc:date>
    </item>
  </channel>
</rss>

