如何在不使用 for 循環的情況下為選定行分配一系列值?大家好
我使用 get rows where() 來獲取一系列行,並希望將 b 列下的行中的值分配給另一列下的相同行,如下所示
行 = dt << 獲取行(列(“b”)[ ] ==“xxx”);
列(“a”)[行] = 列(“b”)[行];
但它不起作用,想知道有沒有辦法在不使用for循環的情況下為選定的行分配一系列值?
謝謝腳本編寫Re: 如何在不使用for循環的情況下為選定的行分配一系列值?這是一個示例,顯示了解決您的問題的一種方法
names default to here(1);
dt=open("$sample_data/big class.jmp");
// Create a new table with the same number of rows and a new
// character column called Gender
dtNew = New Table("New Table", add rows(nrows(dt)),
New Column("Gender",character)
);
// Assign to all rows in big class that are females, the value
// of "Female" to the same rows in New Table
dtNew:Gender[dt<<GET rows="" where=""></GET>Re: 如何在不使用for循環的情況下為選定的行分配一系列值?感謝您的回复。
但不是分配“某個值”,我想在沒有 for 循環的情況下將“一系列值”分配給相應的行。Re: 如何在不使用for循環的情況下為選定的行分配一系列值?其他人可能有更有效的方法,但這是我的解決方案
names default to here(1);
dt=open("$sample_data/big class.jmp");
// Create a new table with the same number of rows and a new
// character column called Gender
dtNew = New Table("New Table", add rows(nrows(dt)),
New Column("Gender",character)
);
// Assign to all rows in big class that are females, the value
// of "Female" to the same rows in New Table
values = dt:sex << get values;
dtNew:Gender << set values(values);
dtNew:Gender[dt<<GET rows="" where=""></GET>