<?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: Create a multiple new columns based on formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/822516#M100221</link>
    <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;Thanks for the input, I am trying to normalize all data point of column by substracting to to the values in column 1. Here I get the values from Column 3, but I get the error showed below. Maybe I need to vectorize the values and make them not as strings? before the difference can be executed?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current data table();
col_names = dt &amp;lt;&amp;lt; get column names(string, continuous);

markerCount = Column(3);
normCount = markerCount - Column(1);
dt &amp;lt;&amp;lt; New Column( "Norm_" || col_names[3], 
		numeric, 
		continuous,
		format( "Fixed Dec", 3, 2 ),
		set each value( as column(normCount))
	);
		//set each value( as column(Column(3)) - column(Column(1)))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 381px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/71119i06611C84D006971E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2024 10:54:04 GMT</pubDate>
    <dc:creator>BioJmPCoder</dc:creator>
    <dc:date>2024-12-13T10:54:04Z</dc:date>
    <item>
      <title>Create a multiple new columns based on formula</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/821618#M100070</link>
      <description>&lt;P&gt;Hi jmp community&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 19000 col x 88 rows containing data continous data values from biomarker expression.&lt;/P&gt;&lt;P&gt;I want to iscreate a new column for each marker containing a formula substracting the biomarker expression value - reference value.&lt;/P&gt;&lt;P&gt;No need to select any rows as I want all rows from both the biomarker and ref.&lt;/P&gt;&lt;P&gt;So it seems pretty straightforward, but I am struggling just to insert the biomarker data into the new column (I have tested the formula but doesnt work either)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code doesnt contain any iterations as I just want to see first if it works for one single column first&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BioJmPCoder_0-1733830087110.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/71008iE9337146DF8BCD99/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BioJmPCoder_0-1733830087110.png" alt="BioJmPCoder_0-1733830087110.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 11:31:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/821618#M100070</guid>
      <dc:creator>BioJmPCoder</dc:creator>
      <dc:date>2024-12-10T11:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create a multiple new columns based on formula</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/821628#M100071</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/63026"&gt;@BioJmPCoder&lt;/a&gt;&amp;nbsp;, can you paste the code using the &amp;lt;JSL&amp;gt; icon in the post buttons?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 11:35:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/821628#M100071</guid>
      <dc:creator>Ben_BarrIngh</dc:creator>
      <dc:date>2024-12-10T11:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create a multiple new columns based on formula</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/821629#M100072</link>
      <description>&lt;P&gt;Here is an example that creates all of the new columns in a data table, using the Blood Pressure sample data table.&amp;nbsp; The script uses 2 different methods to create the new columns to show that different methods can be used to come up with the same results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

// Open a sample data table to use for illustration
dt =
// Open Data Table: Blood Pressure.jmp
// → Data Table( "Blood Pressure" )
Open( "$SAMPLE_DATA/Blood Pressure.jmp" );

// Get all of the numeric continuous column names
colNames = dt &amp;lt;&amp;lt; get column names( string, continuous );

// Method 1
// Cycle through all Numeric, Continuous columns and create
// a new column with the values from the original column,
// using "set each value()"
For Each( {col}, colNames,
	dt &amp;lt;&amp;lt; New Column( col || " Dif1", numeric, continuous,
		format( "Fixed Dec", 3, 0 ),
		set each value( as column(col))
	)
);

// Method 2
// Cycle through all Numeric, Continuous columns and create
// a new column with the values from the original column,
// pulling all of the values for a column into a matrix,
// and then creating a new column and populating the new
// column with the values from the matrix
For Each( {col}, colNames,
	theValues = column( col ) &amp;lt;&amp;lt; get values;
	dt &amp;lt;&amp;lt; New Column( col || " Dif2", numeric, continuous,
		format( "Fixed Dec", 3, 0 )
	);
	column( dt, nCols(dt) ) &amp;lt;&amp;lt; set values( theValues );
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2024 12:16:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/821629#M100072</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-12-10T12:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create a multiple new columns based on formula</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/822516#M100221</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;Thanks for the input, I am trying to normalize all data point of column by substracting to to the values in column 1. Here I get the values from Column 3, but I get the error showed below. Maybe I need to vectorize the values and make them not as strings? before the difference can be executed?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current data table();
col_names = dt &amp;lt;&amp;lt; get column names(string, continuous);

markerCount = Column(3);
normCount = markerCount - Column(1);
dt &amp;lt;&amp;lt; New Column( "Norm_" || col_names[3], 
		numeric, 
		continuous,
		format( "Fixed Dec", 3, 2 ),
		set each value( as column(normCount))
	);
		//set each value( as column(Column(3)) - column(Column(1)))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 381px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/71119i06611C84D006971E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 10:54:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/822516#M100221</guid>
      <dc:creator>BioJmPCoder</dc:creator>
      <dc:date>2024-12-13T10:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a multiple new columns based on formula</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/822576#M100224</link>
      <description>&lt;P&gt;There seems to be some confusion on how to manipulate columns in a data table vs. working with JSL variables.&amp;nbsp; Below is a script that uses 2 methods to create a subtraction of the values in column "BP 6M" with the values in column "BP 8M"&lt;/P&gt;
&lt;P&gt;Method 1 creates column Norm_BP 6M, and method 2 creates column Norm2_BP 6M&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1734091824643.png" style="width: 824px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/71159i51B063845538B6FA/image-dimensions/824x446?v=v2" width="824" height="446" role="button" title="txnelson_0-1734091824643.png" alt="txnelson_0-1734091824643.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have annotated the JSL in hopes to help you understand what the 2 different approaches are doing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

// Open a sample data table to use for illustration
dt =
// Open Data Table: Blood Pressure.jmp
// → Data Table( "Blood Pressure" )
Open( "$SAMPLE_DATA/Blood Pressure.jmp" );
// The data table has the following columns in it
// Subject, Dosec BP 8M, BP 12M, BP 6M, BP 8W, BP 12W, BP 6W, 
// BP 8F, BP 12F, BP 6F, Norm_BP 6M

// Get all of the numeric continuous column names
col_Names = dt &amp;lt;&amp;lt; get column names( string, continuous );
// Get Column Names returns a JMP List of column names
// of the columns that have a Modeling Type of Continuous
// {"BP 8M", "BP 12M", "BP 6M", "BP 8W", "BP 12W", "BP 6W", 
//  "BP 8F", "BP 12F", "BP 6F"}
// Note that the first 2 column in the data table, Subject and Dose
// are not in the list 

// Note: Specifying
//   Column( 1 ) 
// references the 1st column in the data table, which is Subject
// Specifying
//     Column( col_Names[1] )
// references the 1st column in the col_Names List, which is BP 8M

// Method 1
// Create the new column. Set Each Value loops through each
// row in the data table and applies the specified formula
// which is to subtract the value in the 1st column in the 
// col_Names list from the value in the 3rd column in the 
// col_Names list 
dt &amp;lt;&amp;lt; New Column( "Norm_" || col_names[3],
	numeric,
	continuous,
	Format( "Fixed Dec", 3, 2 ),
	set each value( As Column( col_Names[3] ) - As Column( col_Names[1] ) )
);

// Method 2
// Perform the same subtraction, however do it by pulling all of the 
// values from each of the 2 target columns into 2 matrices and then
// use matrix math to do the subtraction into an additional matrix
// and then take those values and put them into the new column

// Create the new column with no values
dt &amp;lt;&amp;lt; New Column( "Norm2_" || col_names[3],
	numeric,
	continuous,
	Format( "Fixed Dec", 3, 2 )
);

// Pull the data from the 2 columns in the data table
matCola = column( col_Names[1]) &amp;lt;&amp;lt; get values;
matColb = column( col_Names[3]) &amp;lt;&amp;lt; get values;
// Subtract the values in matCola from matColb
matResults = matColb - matCola;

// Put the results into the new column
column( "Norm2_" || col_names[3] ) &amp;lt;&amp;lt; set values( matResults);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2024 12:13:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-multiple-new-columns-based-on-formula/m-p/822576#M100224</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-12-13T12:13:50Z</dc:date>
    </item>
  </channel>
</rss>

