根據公式建立多個新列嗨 jmp 社區
我有 19000 col x 88 行,其中包含來自生物標記表達的數據連續數據值。
我想為每個標記建立一個新列,其中包含減去生物標記表達值 - 參考值的公式。
無需選擇任何行,因為我想要生物標記和參考中的所有行。
所以這看起來很簡單,但我只是在努力將生物標記資料插入新列(我已經測試了該公式,但也不起作用)
該程式碼不包含任何迭代,因為我只想先看看它是否適用於單一列

自動化和腳本編寫基礎資料分析與建模資料存取回覆:根據公式建立多個新列您好@BioJmPCoder ,您可以使用以下命令貼上程式碼嗎貼文按鈕中的圖示?
回覆:根據公式建立多個新列以下範例使用「血壓」範例資料表在資料表中建立所有新欄位。該腳本使用 2 種不同的方法來建立新列,以表示可以使用不同的方法得出相同的結果。
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 << 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 << 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 ) << get values;
dt << New Column( col || " Dif2", numeric, continuous,
format( "Fixed Dec", 3, 0 )
);
column( dt, nCols(dt) ) << set values( theValues );
);回覆:根據公式建立多個新列嗨吉姆,
感謝您的輸入,我試圖透過減去第 1 列中的值來標準化列的所有資料點。也許我需要對值進行向量化並使它們不作為字串?差異之前可以執行嗎?
dt = Current data table();
col_names = dt << get column names(string, continuous);
markerCount = Column(3);
normCount = markerCount - Column(1);
dt << 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)))<BR /><BR /><BR /><BR /><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 381px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="image.png" style="width: 381px;"><span class="lia-inline-image-display-wrapper" image-alt="image.png" style="width: 381px;"><img src="https://us.v-cdn.net/6038925/uploads/images/71119i06611C84D006971E/image.png" role="button" title="image.png" alt="image.png" /></span></SPAN></SPAN>
回覆:根據公式建立多個新列對於如何操作資料表中的列與使用 JSL 變數似乎存在一些混淆。下面的腳本使用 2 種方法來建立「BP 6M」列中的值與「BP 8M」列中的值的減法
方法 1 建立列 Norm_BP 6M,方法 2 建立列 Norm2_BP 6M

我對 JSL 進行了註釋,希望能幫助您理解這兩種不同方法的作用
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 << 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 << 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 << 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]) << get values;
matColb = column( col_Names[3]) << get values;
// Subtract the values in matCola from matColb
matResults = matColb - matCola;
// Put the results into the new column
column( "Norm2_" || col_names[3] ) << set values( matResults);