编写 For 循环脚本以将值跨行相乘你好,
我对 JMP 脚本编写相当陌生,并且浏览了许多 jmp 论坛来寻找解决方案,但尚未成功修改针对我的特定问题的解决方案。
我有一个脚本,它生成一个列数未知的表,并希望将行中的每个值(生成的表中只有一行)乘以生成的列(第 1 列 * 第 2 列 * 第 3 列* 等)。 我简化了示例的表格,实际的表格可以有更多的列。
我的循环将每一行乘以下一行,但没有给出所有行相互相乘的最终答案。 我也只想要所有值相乘的最终产品,不需要每个增量值的产品。 很感谢任何形式的帮助。
New Table( "tsp",
Add Rows( 1 ),
New Column( "Row 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.975] )
),
New Column( "Row 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.985] )
),
New Column( "Row 3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.983] )
),
New Column( "Row 4",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.839] )
),
);
Ncol = N col(tsp);
For( i = 1, i <= Ncol, i++,
For( j = i + 1, j <= Ncol, j++,
RTP = Eval( Column( i ) << Get Name ) || " * " || Eval( Column( i+=1 ) << Get Name );
New Column( RTP, Numeric , seteachvalue( Column( i )[] * Column( i+=1 )[]) );
)
);
质量和工艺工程回复:编写 For 循环脚本以跨行乘以值nvm 我发现错误,末尾的括号包含 1,而它应该是空的,我的代码应该是
tsp << New Column("RTP", numeric, continuous, Format(Percent, 1));
for each row(:RTP= Product( i = 2, N Col( tsp), Column( tsp, i )[] ))回复:编写 For 循环脚本以跨行乘以值我尝试将其放入 For Each Row 中,以应对需要使用此公式迭代多行的情况,但它似乎不起作用,并且我不确定我的错误是什么..我得到了正确的值在“RTP”中第一行“A”(86.9%),然后所有其余行显示相同的值(75.5%),而它们应该都不同......
New Table( "tsp",
Add Rows( 5 ),
New Column( "Site",
Character,
"Nominal",
Set Selected,
Set Values( {"A", "B", "C", "D", "E"} )
),
New Column( "Row 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values(
[0.974, 0.872, 0.927,
0.974, 0.9033]
)
),
New Column( "Row 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values(
[0.968, 0.902, 0.931, .,
0.962]
)
),
New Column( "Row 3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values(
[0.944, 0.968, 0.987, ., .]
)
),
New Column( "Row 4",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.9847, 0.9471, ., ., .] )
),
New Column( "Row 5",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.990, 0.994, ., ., .] )
)
);tsp << New Column("RTP", numeric, continuous, Format(Percent, 1));
for each row(:RTP= Product( i = 2, N Col( tsp), Column( tsp, i )[1] ));
回复:编写 For 循环脚本以跨行乘以值New Table() 之后您所需要的只是:
Product( i = 1, N Col( dt ), Column( dt, i )[1] );
回复:编写 For 循环脚本以跨行乘以值先生,您真是太棒了!非常感谢你它工作完美! 我绝对把事情复杂化了哈哈。你太有帮助了!
回复:编写 For 循环脚本以跨行乘以值你工作太辛苦了。以下是我相信你想要的
names default to here( 1 );
dt = New Table( "tsp",
Add Rows( 1 ),
New Column( "Row 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.975] )
),
New Column( "Row 2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.985] )
),
New Column( "Row 3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.983] )
),
New Column( "Row 4",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [0.839] )
),
);
Ncol = N Col( dt ); // or NCol = N Col( data table("tsp"));
value = 1;
For( i = 1, i <= Ncol, i++,
value = Column( dt, i )[1] * value
);
Show( value );