如何在不使用for迴圈的情況下為選取的行分配一系列值?大家好
我使用 get rows where() 來取得一系列行,並希望將 b 列下的行中的值指派給另一列下的相同行,如下所示
rows = dt << get rows where (column("b")[ ] == "xxx");<BR />column ("a")[rows] = column ("b") [rows];
但它不起作用,想知道有什麼方法可以在不使用for循環的情況下為選定的行分配一系列值?
謝謝
實驗設計回覆:如何在不使用 for 迴圈的情況下為選定的行指派一系列值?這是一個很好的提示。
多謝!回覆:如何在不使用 for 迴圈的情況下為選定的行指派一系列值?數據表下標可能就是您正在尋找的。 您可能可以使用類似 dt[rows,{a}] = dt[rows,{b}]; 的內容其中 rows 是具有行索引的矩陣,{a} 和 {b} 是列列表。 您還需要顯式 dt,該顯式 dt 在開啟表時由 open() 返回,或由創建新表的其他函數(如 subset() 等)返回。
回覆:如何在不使用 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>回覆:如何在不使用 for 迴圈的情況下為選定的行指派一系列值?感謝您的回覆。
但我不想分配“某個值”,而是想在沒有 for 迴圈的情況下將“一系列值”分配給相應的行。回覆:如何在不使用 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>