對子集列執行公式我創建了一個腳本來創建較大表的子集表,但它無法正常工作。 我的目標是讓使用者在子集表中選擇他們想要的列,然後讓腳本在將資料放入新表之前對列執行公式。到目前為止,我的腳本將拉出用於使用者互動的對話框,但是當我選擇對話框中的列時,它們並不是顯示在子集表中的列。 我不確定我的問題出在哪裡。 (注意:使用者將選擇其中包含資料的列,而不是範例信息,因此在範例中,列名稱以“Column 10...”開頭。)
此外,我不確定在哪裡插入公式。 基本上,使用者從對話方塊中選擇的列將有一些帶有< 符號的單元格,對於新的子集表,我希望任何沒有小於符號的單元格變為零,並且任何帶有< 符號的單元格都具有< 符號刪除了僅將其旁邊的數字放置在子集表中的情況。 因此,新的子集表的檢測值為零,未檢測化合物的檢測極限為零。
到目前為止,這是我的腳本。
Names Default To Here( 1 );
dt = Data Table("Example Data");
col_dlg = new window("Column Select",
panelbox("Select columns to create NonDetect table with",
col_clist = collistbox(all, width(200)),
buttonbox("Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset(Output Table("NonDetect"),columns(col_clist));
col_dlg << close window;
)
)
);感謝您的任何幫助!
回覆:對子集列執行公式現在,您有機會向討論社群的貢獻者付費......深入研究腳本指南和腳本索引,成為經驗豐富的用戶,並透過您的參與來回報。
回覆:對子集列執行公式成功了! 非常感謝您的時間和耐心。 我真的很感激!
萊西
回覆:對子集列執行公式事實證明,Substr() 函數不適用於所選行(不知道為什麼),所以我稍微更改了程式碼並對其進行了測試(顯然我沒有測試我的上一個版本)
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Select all of the currently non selected columns and unselect the current ones
dt2 << select where( Contains( As Column( dt2, selected_column_list[i] ), "<" ) == 0 );
// Set for the target column all of the currently selected rows to "0"
Column( dt2, selected_column_list[i] )[dt2 << get selected rows] = "0";
// Find the rows with the "<" in them
dt2 << invert row selection;
selRows = dt2 << get selected rows;
//selRows= dt2 << Get Rows Where(Contains(As Column( dt2, selected_column_list[i] ),"<" )==1);
// Get rid of the "<" making the value a valid numeric value
For( k = 1, k <= N Rows( selRows ), k++,
Column( dt2, selected_column_list[i] )[selRows[k]] = Substr( As Column( dt2, selected_column_list[i] )[selRows[k]], 2 )
);
// Convert the column to a numeric/continuous column
Column( dt2, selected_column_list[i] ) << data type( numeric ) << modeling type( continuous );
);
col_dlg << close window;
)
)
);回覆:對子集列執行公式也許我把 ( 放在錯誤的位置? 這就是我現在所擁有的。
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Select the rows where there is a "<" for the target column
dt2 << Select where(Contains(As Column( dt2, selected_column_list[i] ),"<" )==1);
// Get rid of the "<" making the value a valid numeric value
Column( dt2, selected_column_list[i] )[dt2 << get selected rows ()] =
substr(As Column( dt2, selected_column_list[i] ),2);
// Select all of the currently non selected columns and unselect the current ones
dt2 << invert row selection;
// Set for the target column all of the currently selected rows to "0"
Column( dt2, selected_column_list[i] )[dt2 << get selected rows ()] = "0";
// Convert the column to a numeric/continuous column
Column( dt2, selected_column_list[i] ) << data type( numeric ) <<
modeling type( continuous );
);
col_dlg << close window;
)
)
);回覆:對子集列執行公式謝謝你快速的回覆! 我嘗試了 2,但最終檢測到的值為零,任何帶有 < 符號的單元格均為空白。 與 1 得到的結果相同。
回覆:對子集列執行公式哎呀.....我的錯誤,將 substr() 函數中的“1”更改為“2”,這樣就可以修復它
回覆:對子集列執行公式您為第二個表發送的第二個代碼似乎不起作用。 我花了幾個小時嘗試不同的事情。 我注意到缺少兩個 (。 這有助於程式碼正常運行,但是刪除“<”符號的程式碼部分似乎無法正常運行。 如果我刪除那段程式碼,表格最終會偵測到的值為 0,且 ND 值仍然完好無損,並帶有 < 符號。 我已經嘗試擺弄它,但還沒有弄清楚。 有什麼線索嗎? 
謝謝!
回覆:對子集列執行公式這是處理第二種情況的程式碼
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Select the rows where there is a "<" for the target column
dt2 << Select where(Contains(As Column( dt2, selected_column_list[i] ),"<" )==1);
// Get rid of the "<" making the value a valid numeric value
Column( dt2, selected_column_list[i] )[dt2 << get selected rows )] =
substr(As Column( dt2, selected_column_list[i] ),1);
// Select all of the currently non selected columns and unselect the current ones
dt2 << invert row selection;
// Set for the target column all of the currently selected rows to "0"
Column( dt2, selected_column_list[i] )[dt2 << get selected rows )] = "0";
// Convert the column to a numeric/continuous column
Column( dt2, selected_column_list[i] ) << data type( numeric ) <<
modeling type( continuous );
);
col_dlg << close window;
)
)
);回覆:對子集列執行公式這對於“檢測”表非常有用,因此對於我的第二個表,我想將變為零的值切換到零,因此我認為這種方法行不通。 我想保留帶有 < 符號的單元格,並將其餘單元格設為零。 然後我想刪除 < 符號,只留下數值。 在我的腦海中,我想我會按照你的方式進行循環,然後添加 if/else 語句?
感謝您發布 if/else 語句。 我的問題是在 else 的列名之前沒有 num() !
回覆:對子集列執行公式這是腳本中的一個更改,我認為您可能會發現這是一個很好的方法。我將您想要做的解釋為建立數字列,其中包含您選擇的字元列中的值,但如果這些值包含「<」符號,請將這些條目設為零 (0)。下面的腳本可以做到這一點,而無需建立新列。它將列轉換為數字,並將“<”儲存格設為零。
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
// Loop across the columns in the new data table and convert them to numeric
// Cells with nonnumeric values will be set to Missing Values, which then can
// be identified and set to 0
For( i = 1, i <= N Items( selected_column_list ), i++,
// Change the column to numeric/continuous
// The names in the data table are very complex, containing symbols, etc.
// that JMP will confuse as operators. Therefore, using the Column()
// function, or a :Name(" ") function to wrap around the column name
// needs to be used
Column( dt2, selected_column_list[i] ) << data type( numeric ) <<
modeling type( continuous );
// Now find all of the rows in the table that have Missing Values
// in the target column, and then set them all to "0" in one
// statement
Column( dt2, selected_column_list[i] )[dt << get rows where(
Is Missing( As Column( dt2, selected_column_list[i] ) )
)] = 0;
);
col_dlg << close window;
)
)
);
您可以建立新列並設定公式,如您在上次回應中所示。您所提供的內容遇到的問題是處理複雜的列名稱。 這是如何工作的
If( Contains( :Name( "Column 10 1,2,3,4,6,7,8-HpCDD" ), "<" ),
0,
Num( :Name( "Column 10 1,2,3,4,6,7,8-HpCDD" ) )
)
回覆:對子集列執行公式我認為這就是我的麻煩所在,我非常精通 Excel,並且已經用它進行了 9 年的所有數據分析。 我只是想轉移,但我在 jmp 中的 if/then 語句(除其他外)中遇到了困難。 我會用excel來寫,也許你能幫忙?
我將製作其中兩個子集表。 一種用於偵測到的值,一種用於未偵測到的值。 對於偵測到的值,我會執行 if/then 語句,例如 =if(isnumber(J2),J2,0)。 對於未偵測到的值,我會執行類似 =if(isnumber(J2),0,J2) 的操作。
我試圖在 JMP 中將其切換為
如果(包含(:第 10 列 1,2,3,4,6,7,8-HpCDD , “<” ), 0 ,:第 10 列 1,2,3,4,6,7,8-HpCDD )
但即使我自己創建一個列並插入公式,它似乎也不起作用。
所以基本上,在我的腳本中,我將包括兩部分,一部分用於 NonDetect 表,另一部分用於 Detect 表,我希望使用 if then 語句對列進行這樣的轉換? 最後,我將把兩個資料表傳送到 R,以使用 NonDetect 子集中剩餘的 DL 來估算非偵測值。 我希望這能解釋一下?
回覆:對子集列執行公式你要計算的公式是什麼?真的需要建立一個新列嗎?請記住,這不是 Excel。要產生值或結果,不必將它們放入列中......還有其他結構。您能更詳細地描述您想要做什麼嗎?
回覆:對子集列執行公式啊,那行得通。
有沒有辦法在將資料放入新表之前完成資料公式? 如果沒有,我的想法是在子集表中建立新列,在新列中完成計算,然後刪除原始列(使用腳本)。 有沒有更有效的方法來做到這一點?
謝謝!
回覆:對子集列執行公式您正在引用顯示物件 col_clist,而不是已放入 Selected_column_list 中的它的內容。
Names Default To Here( 1 );
dt = Data Table( "Example Data" );
col_dlg = New Window( "Column Select",
Panel Box( "Select columns to create NonDetect table with",
col_clist = Col List Box( all, width( 200 ) ),
Button Box( "Ok",
selected_column_list = col_clist << getselected;
dt2 = dt << Subset( Output Table( "NonDetect" ), columns( selected_column_list ) );
col_dlg << close window;
)
)
);