sort 명령은 현재 DataFrames을 지원하지 않습니다. 나는이 주위에 DataFrame 열 (DataSeries) 벡터로, output = permutation
옵션을 사용하여 벡터 정렬 및 그 결과에 의해 DataFrame 인덱싱.
Mydata[ sort(convert(Mydata[Value], Vector), output = permutation), .. ];
Mydata[ [4, 2, 1, 3], .. ];
반환 : 다음 값 컬럼의 오름차순으로 정렬 된 DataFrame을 반환이 결과에 의해 원래의 DataFrame 색인
[4, 2, 1, 3]
:
Mydata := DataFrame(<<2,1,3,0>|<"Red","Blue","Green","Orange">>, columns = [Value,Color]);
sort(convert(Mydata[Value], Vector), output = permutation);
반환 : 귀하의 예제를 사용 :
[ Value Color ]
[ ]
[4 0 "Orange"]
[ ]
[2 1 "Blue" ]
[ ]
[1 2 "Red" ]
[ ]
[3 3 "Green" ]
즉, DataFrames를 여러 번 정렬해야하므로 대부분의 데이터 세트에서 작동하는 것처럼 보이는 프로 시저를 만들었습니다. 이 절차에서는 sort 명령을 사용하는 것과 비슷한 방식을 사용하지만 Maple DataFrame 개체 자체에서 작동하므로 데이터 변환이 필요하지 않습니다. 이렇게하려면 내부 DataFrame 데이터 개체로 직접 작업하려면 kernelopts(opaquemodules = false)
으로 설정해야합니다 (매트릭스 및 벡터 중간으로 변환 할 수도 있지만이 방법은 생성되는 중복 내부 데이터의 양을 제한합니다) :
예를 들어
DSort := proc(self::{DataFrame,DataSeries}, {ByColumn := NULL})
local i, opacity, orderindex;
opacity := kernelopts('opaquemodules' = false):
if type(self, ':-DataFrame') and ByColumn <> NULL then
orderindex := sort(self[ByColumn]:-data, ':-output' = ':-permutation', _rest);
elif type(self, ':-DataSeries') and ByColumn = NULL then
orderindex := sort(self:-data, ':-output' = ':-permutation', _rest);
else
return self;
end if;
kernelopts(opaquemodules = opacity): #Set opaquemodules back to original setting
if type(self, ':-DataFrame') then
return DataFrame(self[ orderindex, .. ]);
else
return DataSeries(self[ orderindex ]);
end if;
end proc:
:
DSort(Mydata, ByColumn=Value);
반환 : 그래서 또한 문자열에서 작동이
[ Value Color ]
[ ]
[4 0 "Orange"]
[ ]
[2 1 "Blue" ]
[ ]
[1 2 "Red" ]
[ ]
[3 3 "Green" ]
,이 작동해야합니다. 이 과정에서
[ Value Color ]
[ ]
[2 1 "Blue" ]
[ ]
[3 3 "Green" ]
[ ]
[4 0 "Orange"]
[ ]
[1 2 "Red" ]
, (난 당신이 또한 오름차순 또는 옵션을 내림차순으로 추가 할 수 있다는 것을 의미 sort
명령에 추가 인수를 전달, 그래서 당신은 '가치'내림차순으로 DataFrame를 반환 DSort(Mydata, ByColumn=Value, `>`);
을 할 수 이 문자열을 잘 재생되지 않는 것).