選擇值並複製到新列中嘿,
我正在嘗試自動化(看起來相當簡單)值選擇、列創建和復制/粘貼但是,我找不到合適的腳本編譯。
1)我需要創建3 個新專欄從一個值中添加不同的選擇相同來源列到這 3 個新列中的每一列並創建一個子集每個選擇的當所有列都填滿時。
2) 子集的名稱應對應於原始源文件的標題加上新的附錄。
意識到:
我擁有的數據文件中列的位置和行數各不相同,但是名稱都是相同的。
我嘗試了這兩個腳本,這當然是不正確的,但我不知道到底要更改什麼才能使其正常工作。 有什麼建議麼?
版本1:
Names Default To Here( 1 );
dt = Current Data Table();
//Select values to copy into new column
vals 1 = Select Where (:p-value (two-sided test)2 <= 0,09); //it seems that the "2" in the column name is confusing, but unfortunately, it would take a long time to go through all tables and change the column name
// Put these in a new column 1
dt = NewColumn("sign_0,09", Numeric, Continuous, Values(vals1));
Wait( 5 );
//Column 2
vals 2 = Select Where (:p-value (two-sided test)2 <= 0,05);
dt<<GET selected="" rows="" dt="NewColumn("sign_0,05"," numeric=""></GET>
版本2:
Names Default To Here( 1 );
dt = Current Data Table();
dt << :p-value (two-sided test)2 = [1,?]; //the end row varies and must be found automatically
results << New Column("sign_0,09", Numerical, Continuous);
For( i = 1, i <= NItems( "p-value (two-sided test)2"), i++,
results << Select Where (:p-value (two-sided test)2 <= 0,09) );
selRows = results << getSelectedRows;
AsColumn( results, "sign_0,09" )[selRows] = "p-value (two-sided test)2"[i];
//same process for 2 other new columns
dt<<SUBSET dt=""><< Select where :sign_0,09 != "";
dt<< Get selected rows
//the new name should be automatically given, too, is that possible?
dt << Subset( Output Table( "name as in original file plus _0,09 at the end" ), Selected Rows( 1 ), selected columns( 0 ) );
//same process for other 2 columns</SUBSET>
我很高興找到一個解決方案,因為到目前為止,在線程中經常會復制/粘貼到新的數據表中,但是,“從不”到新列中,而且大多數情況下它似乎與字符串選擇有關。 不確定該選擇對於數字數據是否同樣有效。
謝謝你的幫助!
回复:值選擇並複製到新列中嘿,這是沒有顯示功能的完整版本,因為這些功能對我來說沒有任何用處。
感謝您的幫助!
dt = Current Data Table(); // Assuming the data table is open
/* Step 1 - add 3 columns */
dt << New Column("sign_0,09",Numeric,Continuous)
<< New Column("sign_0,05",Numeric,Continuous)
<< New Column("sign_0,01",Numeric,Continuous);
// Getting the values of column of interest
ColVals = dt:Name("p-value (two-sided test) 2") << Get Values;
// Set up a dummy matrix
Dummy = J(NRows(dt),1,.);
// All Rows
AllRows = Index(1,NRows(dt),1);
/* Step 2 - Select from the column based on conditions */
/* This could also be replaced by loop */
SR1 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.09);
//do not change "." to "," as the programme uses "." for background calculation
Dummy[SR1,0] = ColVals[SR1];
dt:Name("sign_0,09") << Set Values(Dummy);
// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);
SR2 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.05);
Dummy[SR2,0] = ColVals[SR2];
dt:Name("sign_0,05") << Set Values(Dummy);
// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);
SR3 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.01);
Dummy[SR3,0] = ColVals[SR3];
dt:Name("sign_0,01") << Set Values(Dummy);
/* End of Step 2 */
/* Step 3 */
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */
回复:值選擇並複製到新列中嘿,這是沒有顯示功能的完整版本,因為這些功能對我來說沒有任何用處。
感謝您的幫助!
dt = Current Data Table(); // Assuming the data table is open
/* Step 1 - add 3 columns */
dt << New Column("sign_0,09",Numeric,Continuous)
<< New Column("sign_0,05",Numeric,Continuous)
<< New Column("sign_0,01",Numeric,Continuous);
// Getting the values of column of interest
ColVals = dt:Name("p-value (two-sided test) 2") << Get Values;
// Set up a dummy matrix
Dummy = J(NRows(dt),1,.);
// All Rows
AllRows = Index(1,NRows(dt),1);
/* Step 2 - Select from the column based on conditions */
/* This could also be replaced by loop */
SR1 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.09);
//do not change "." to "," as the programme uses "." for background calculation
Dummy[SR1,0] = ColVals[SR1];
dt:Name("sign_0,09") << Set Values(Dummy);
// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);
SR2 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.05);
Dummy[SR2,0] = ColVals[SR2];
dt:Name("sign_0,05") << Set Values(Dummy);
// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);
SR3 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.01);
Dummy[SR3,0] = ColVals[SR3];
dt:Name("sign_0,01") << Set Values(Dummy);
/* End of Step 2 */
/* Step 3 */
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */
回复:值選擇並複製到新列中@傑夫·珀金森
謝謝杰夫,
我讀你的文章太晚了。 我剛剛將創建子集部分添加到您建議的選擇中,除了自動名稱創建之外,它運行得很好。 感謝您的建議。
dt = Current Data Table();
dt << New Column( "sign_0,09",
Numeric,
"Nominal",
Format( "Best", 9 ),
Formula(
If( :Name( "p-value (two-sided test) 2" ) <= 0.09,
:Name( "p-value (two-sided test) 2" )
)
)
);
dt << New Column( "sign_0,05",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( :Name( "p-value (two-sided test) 2" ) <= 0.05,
:Name( "p-value (two-sided test) 2" )
)
)
);
dt << New Column( "sign_0,01",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( :Name( "p-value (two-sided test) 2" ) <= 0.01,
:Name( "p-value (two-sided test) 2" )
)
)
);
/* Step 3 */
// We already have the rows that meet the conditions
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */ 回复:值選擇並複製到新列中回复:值選擇並複製到新列中@uday_guntupalli
我用我的數據(您的版本以及交換的建議)運行了腳本@馬克貝利),它可以創建列並將選定的數據放入新列中。
但是,顯示所選行的最後一部分(見下文)不起作用。 我通過“選擇位置並創建子集”對其進行了調整。
/* Step 3 */
// We already have the rows that meet the conditions
Show(SR1);
Show(SR2);
Show(SR3);
/* End of Step 3 */
/* Step 3 */
dt << Select Where (Name("p-value (two-sided test)2") <= 0.09);
dt << Subset( Output Table( "new_0,09" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.05);
dt << Subset( Output Table( "new_0,05" ), Selected Rows( 1 ), selected columns( 0 ) );
dt << Select Where (Name("p-value (two-sided test)2") <= 0.01);
dt << Subset( Output Table( "new_0,01" ), Selected Rows( 1 ), selected columns( 0 ) );
/* End of Step 3 */
回复:值選擇並複製到新列中感謝您發布更多詳細信息,這對一些人有幫助。我不會嘗試創建新列並通過 JSL 填充值,而是使用以下公式創建三個基於公式的新列:
If( :Name( "p-value (two-sided test) 2" ) <= 0.09,
:Name( "p-value (two-sided test) 2" )
)

dt = Open( "seas_ratio_1_monthly.jmp" );
dt << New Column( "sign_0.09",
Numeric,
"Nominal",
Format( "Best", 9 ),
Formula(
If( :Name( "p-value (two-sided test) 2" ) <= 0.09,
:Name( "p-value (two-sided test) 2" )
)
)
);
dt << New Column( "sign_0.05",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( :Name( "p-value (two-sided test) 2" ) <= 0.05,
:Name( "p-value (two-sided test) 2" )
)
)
);
dt << New Column( "sign_0.01",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( :Name( "p-value (two-sided test) 2" ) <= 0.01,
:Name( "p-value (two-sided test) 2" )
)
)
);
但是,我必須承認,我仍然不確定僅包含在特定級別上重要的行的數據表的價值。 您將如何使用這些表格? 他們是否需要所有三個顯著性指示符列(即sign_0,09;sign_0,05;和sign_0,01)? 如果不是,您可以避免一起創建這些列,而只對小於每個級別的行進行子集化。 您能告訴我們更多關於您的最終目標以及為什麼您想要您所描述的數據表嗎? 我們也許能夠提供更簡單的方法。
回复:值選擇並複製到新列中我看到了這種方法,但有一種更簡單的方法,涉及更改所選行的狀態。 而不是這個:
SR1 = dt << Select Where(:Name("p-value (two-sided test) 2") <= 0.09) << Get Selected Rows; <BR />// You can edit this to conform to european convention of 0,09
dt << Clear Select;
你可以使用這個:
SR1 = dt << Get Rows Where(:Name("p-value (two-sided test) 2") <= 0.09)
// You can edit this to conform to european convention of 0,09
這樣您就不會干擾當前的行選擇。
回复:值選擇並複製到新列中看起來很棒。 我會盡快測試。
如果您引用 3 個新列中的公共元素,那麼這只是關於將添加到每列的選定值的情況!
例如,選擇 <= 0,01 的值也將出現在 0,05 和 0,09 的列中,而 <= 0,05 的值也將出現在 0,09 中。
簡化:
A = [ 0,01 , 0,05 ,0,09]
B = [ 0,01 , 0,05 ]
C = [ 0,01 ]
但是,不會有任何其他模式或類型的“所有三行中每隔一行都相等”的結構。
因此,是的,也許有一種方法可以使用矩陣並使整個過程更加順利。
A <SPAN class="token operator">=</SPAN> <SPAN class="token punctuation">[</SPAN><SPAN class="token number">1</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">2</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">3</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">4</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">5</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">6</SPAN><SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">;</SPAN>
B <SPAN class="token operator">=</SPAN> <SPAN class="token punctuation">[</SPAN><SPAN class="token number">1</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">2</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">3</SPAN><SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">;</SPAN>
C <SPAN class="token operator">=</SPAN> <SPAN class="token punctuation">[</SPAN><SPAN class="token number">3</SPAN><SPAN class="token punctuation">,</SPAN><SPAN class="token number">5</SPAN><SPAN class="token punctuation">]</SPAN><SPAN class="token punctuation">;</SPAN>
回复:值選擇並複製到新列中@帕科,
好的,這應該能讓你完成 90% 的任務。
dt = Current Data Table(); // Assuming the data table is open
/* Step 1 - add 3 columns */
dt << New Column("sign_0,09",Numeric,Continuous)
<< New Column("sign_0,05",Numeric,Continuous)
<< New Column("sign_0,01",Numeric,Continuous);
// Getting the values of column of interest
ColVals = dt:Name("p-value (two-sided test) 2") << Get Values;
// Set up a dummy matrix
Dummy = J(NRows(dt),1,.);
// All Rows
AllRows = Index(1,NRows(dt),1);
/* Step 2 - Select from the column based on conditions */
/* This could also be replaced by loop */
SR1 = dt << Select Where(:Name("p-value (two-sided test) 2") <= 0.09) << Get Selected Rows; // You can edit this to conform to european convention of 0,09
dt << Clear Select;
Dummy[SR1,0] = ColVals[SR1];
dt:Name("sign_0,09") << Set Values(Dummy);
// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);
SR2 = dt << Select Where(:Name("p-value (two-sided test) 2") <= 0.05) << Get Selected Rows; // You can edit this to conform to european convention of 0,05
dt << Clear Select;
Dummy[SR2,0] = ColVals[SR2];
dt:Name("sign_0,05") << Set Values(Dummy);
// Re-initialize dummy matrix
Dummy = J(NRows(dt),1,.);
SR3 = dt << Select Where(:Name("p-value (two-sided test) 2") <= 0.01) << Get Selected Rows; // You can edit this to conform to european convention of 0,01
dt << Clear Select;
Dummy[SR3,0] = ColVals[SR3];
dt:Name("sign_0,01") << Set Values(Dummy);
/* End of Step 2 */
/* Step 3 */
// We already have the rows that meet the conditions
Show(SR1);
Show(SR2);
Show(SR3);
/* End of Step 3 */ <BR />@傑夫·珀金森,
有沒有一種簡單的方法可以找到矩陣之間的共同元素? 也許 Design() 可能有幫助,但是你能提供一個例子嗎
A = [1,2,3,4,5,6];
B = [1,2,3];
C = [3,5];
// The common element would be 3
我知道我可以使用關聯數組和相交功能,但矩陣不應該有一種簡單的方法來確定常見/不常見元素。
回复:值選擇並複製到新列中嗨傑夫,
也謝謝你來看一看。
我在上面的回復中附上了文件! 我希望他們能澄清我的問題。
回复:值選擇並複製到新列中回复:值選擇並複製到新列中嘿,
非常感謝您的意見。 了解這一點已經非常有幫助了。
對於腳本複制錯誤,我深表歉意。 下次我會記住的。
為了更清楚地說明我正在嘗試做什麼,我附上了結果應該是什麼樣子的逐步概述。 我希望指南能夠更加清晰。
我還附上了 jmp 格式的示例。
謝謝您的幫助!
回复:值選擇並複製到新列中我已經閱讀了你對你想要做的事情的描述,但如果沒有具體的例子,我很難理解它。 此外,由於您的 JSL 沒有執行您希望它執行的操作,因此很難使用它來猜測如何幫助您。
您能否發布一些有關您正在嘗試執行的操作的更多詳細信息,最好是有問題的數據表的屏幕截圖以及您希望最終得到的結果? 我認為這將有助於我們社區更直接地為您提供幫助。
謝謝。
回复:值選擇並複製到新列中@帕科,
讓我們看看我可以如何嘗試提供幫助。 首先,我這邊的要求是,當您粘貼代碼時,請使用“JSL”代碼塊進行粘貼,以便社區成員可以輕鬆閱讀您的代碼。 現在,一旦我們解決了這個問題,就可以查看您的代碼:
1. vals 1 = 選擇其中 (:p 值(雙面測試)2 <= 0,09); / /看起來列名中的“2”很混亂,但不幸的是,要遍歷所有表並更改列名需要很長時間
- 當您的列有一個像這樣的複雜名稱並且不想更改它時,建議使用 name() 。所以上面的行應該重寫為:
vals1 = Select Where (Name("p-value (two-sided test)2 ")<= 0,09); // I don't know if you are using European convention for the comma instead of decimal2.現在,select where語句是向數據表發出的消息,因此上面的代碼應該進一步細化為:
vals1 = dt << Select Where (Name("p-value (two-sided test)2") <= 0,09); 如果您願意嘗試這些建議並提供示例數據集,我也可以嘗試解決其他問題。