A問題關於使用列名集。 您可以使用 JSL 的關聯數組來執行集合操作。 方法 <
// make three sets
rgb = associativearray({"red","green","blue"});
cmy = associativearray({"cyan","magenta","yellow"});
bw = associativearray({"black","white"});
// join them together
all = rgb;
all<<INSERT></INSERT>
問題是根據列名的集合提出的,這個例子使用關聯數組集合操作<<刪除得到所有列的集合和包含字母“i”的列的集合之間的差異。
// keep only the columns with an "i" in the name
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
allnames = dt << getcolumnnames( "string" );
inames = {};
For( i = 1, i <= N Items( allnames ), i++,
If( Contains( allnames[i], "i" ),
Insert Into( inames, allnames[i] )
)
);
allset = Associative Array( allnames ); // {"name", "age", "sex", "height", "weight"}
iset = Associative Array( inames ); // {"height", "weight"}
allset << Remove( iset ); // the "not i" set...
notinames = allset<<GETKEYS></GETKEYS>
這很好。我沒想過要使用這樣的關聯數組。過去我曾遇到過使用對象引用列表的情況,我想搜索整個列表以消除滿足特定條件的對象。使用列表操作很慢,控制邏輯也很複雜。我可以看到這將如何使它變得更容易。我正在復制並粘貼您的示例代碼以添加到我的“JSL 收藏”以供將來參考!