脚本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 )[]) );
)
);
脚本编写Re:脚本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 );Re:脚本For循环可在行中相乘值先生,您真是太好了!非常感谢,它非常完美! 我肯定是使事情复杂化了哈哈。您非常有帮助!
Re:脚本For循环可在行中相乘值在New Table()之后,您需要做的就是:
Product( i = 1, N Col( dt ), Column( dt, i )[1] );
Re:脚本For循环可在行中相乘值我试图将其放入“每行”中,以防我需要使用该公式迭代多行但它似乎无法正常工作并且我不确定我的错误是..我得到正确的值的情况。在第一行“ A”的“ RTP”中(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] ));