在數字和文字同時存在的情況下,如何才能實現正確的排序?如以下 JSL 所示,當僅存在數字時,可以按升序正確排序;但是,當與文字混合時,在排序之前轉換為數字會導致問題。可以用什麼方法來解決這個問題呢?
stepList = {"2", "3", "10", "9", "1"};
stepListSort = Sort List( stepList );
stepListNum = {};
For( i = 1, i <= N Items( stepList ), i++,
Insert Into( stepListNum, Num( stepList[i] ) )
);
stepListNumSort = Sort List( stepListNum );
stepListWithString = {"2", "3", "10_New", "9", "1"};
stepListWithStringSort = Sort List( stepListWithString );
Show( stepListWithSting );
stepListNum = {};
For( i = 1, i <= N Items( stepList ), i++,
Insert Into( stepListNum, Num( stepListWithString[i] ) )
);
stepListWithStringNumSort = Sort List( stepListNum );基礎資料分析與建模Re: 當數字和文字同時存在的情況下,如何才能實現正確的排序呢?JMP 在不同的地方使用不同的排序方式(我至少有一篇舊帖子詢問過這一點,但可能很難找到)。您可以嘗試通過資料表
Names Default To Here(1);
stepListWithString = {"2", "3", "10_New", "9", "1"};
dt = New Table("A",
New Column("A", Character, Nominal, Values(stepListWithString))
);
dt << Sort(By(:A), Replace Table, Order(Ascending));
stepListWithStringSort = dt[0, 1];
Close(dt, no save);
show(stepListWithStringSort);
// stepListWithStringSort = {"1", "2", "3", "9", "10_New"};