腳本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] ));