选择值并复制到新列中嘿,
我正在尝试自动化(看起来相当简单)值选择、列创建和复制/粘贴但是,我找不到合适的脚本编译。
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); 如果您愿意尝试这些建议并提供示例数据集,我也可以尝试解决其他问题。