你好,
我有一張如下表。
ABC ..n 列
1 2 3
7 6 4
3 7 9
.
.
m 行
我想編寫一個腳本,以便對於每一列“第 n 行的值 = 第 n 行的值 - 第一行的值”,最後將第一行重置為 0。 所以最後我的桌子應該看起來像
美國廣播公司
0 0 0..
6 4 1
2 5 6
.
.
有人可以幫我編寫這樣一個操作的腳本嗎? 謝謝
這裡有幾種循環的方法........存在更多方法,但我會讓其他人展示它們
Names Default To Here( 1 );
// Open the data table
dt1 = Open( "$SAMPLE_DATA\Blood Pressure.jmp" );
// Create a second copy
dt2 = dt1 << subset( selected columns( 0 ), selected rows( 0 ) );
// Get all numeric, continuous column names
colList = dt1 << get column names( string, numeric, continuous );
// Loop across all numeric, continuous columns and use a
// matrix operation to handle the math
For( i = 1, i <= N Items( colList ), i++,
mat = Column( dt1, colList[i] ) << get values;
mat = mat - mat[1];
Column( dt1, colList[i] ) << set values( mat );
);
// Now do the same thing looping with the data in place
// Loop across all numeric, continuous columns
For( i = 1, i <= N Items( colList ), i++,
// Go through each row, from the bottom to the top to subtract
// the value of the first row from each rows value
For( k = N Rows( dt2 ), k >= 1, k--,
Column( dt2, colList[i] )[k] = Column( dt2, colList[i] )[k] - Column( dt2, colList[i] )[1]
)
);