jsl : 변수 접미사가있는 그룹 및 스택 열안녕하세요,
필자는 스크립팅에 익숙하지 않고 다음과 같은 도움을 주시면 감사하겠습니다.
변수 이름 접미사를 사용하여 열을 그룹화하고 스택 할 수있는 스크립트를 작성하려고합니다. 내 테이블은 x, y, area, perimeter, AR로 시작하고 접미사 1, 2, 3 등이있는 변경되지 않은 이름 (예 : 소스, 프레임)과 기타 (최대 수백 개)의 이름이있는 몇 개의 열로 구성됩니다. 그래서 보통 다음과 같이 보일 것입니다 ...
소스, 프레임, x1, y1, ar1, 영역 1, angle1, 둘레 1, x2, y2, ar, area2, angle2, 둘레 2, .... 등등 ...
번호에 관계없이 모든 ex, ys 등을 그룹화하는 스크립트를 작성하는 데 많은 도움을 주시면 감사하겠습니다. 이 후 x, y, area, perimeter에 대한 데이터가있는 접미사와 다른 열을 나타내는 하나의 열을 스택에 넣으려고합니다.
잘만되면 나는 나 자신을 명백하게했다.
따라하기 쉽도록 작은 테이블을 붙이고 있습니다.
어떤 도움을 주셔서 감사합니다.
안드레
재 : jsl : 변수 접미사가있는 열과 그룹을 그룹화합니다.다음은 내가 원하는대로 스크립트를 작성한 것입니다.
Names Default To Here( 1 );
dt = Current Data Table();
// Get all of the column names so we can get a count of the number of
// X and Y columns found
All Columns = dt << get column names;
// Loop through and find the number of Xnn columns & Ynn columns
XList = YList = {};
For( i = 1, i <= N Items( All Columns ), i++,
If( Uppercase( Substr( All Columns[i], 1, 1 ) ) == "X" & Is Missing( Num( Substr( All Columns[i], 2 ) ) ) == 0,
Insert Into( XList, Num( Substr( All Columns[i], 2 ) ) )
);
If( Uppercase( Substr( All Columns[i], 1, 1 ) ) == "Y" & Is Missing( Num( Substr( All Columns[i], 2 ) ) ) == 0,
Insert Into( YList, Num( Substr( All Columns[i], 2 ) ) )
);
);
start = min(XList);
end = max(XList);
// Error checking
If(end!=max(YList) | start!=min(YList) | N items(XList)!=N Items(YList),
dialog("errors in column matching found"); throw());
// Create Column Lists
For(i=1,i<=nItems(XList),i++,
XList[i]=column("X" || char(XList[i]));
YList[i]=column("Y" || char(YList[i]));
);
// Combine the lists
Stack Columns = XList || YList;
// Stack the data
dtStacked =dt << Stack(
columns( Stack Columns ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Eliminate missing rows( 1 ),
Drop All Other Columns( 1 ),
Number of Series( 2 ),
Contiguous
);
// Create the Suffix column
dtStacked << New Column("Suffix",character,formula(substr(:Label,2)));
// Remove the formula and leave the calculated value
dtStacked:Suffix << delete property("formula");
// Rename the columns, and delete unneeded columns
dtStacked:Data << Set Name("X");
dtStacked:Data 2 << Set Name("Y");
dtStacked << delete columns({"Label","Label 2"});