두 개의 데이터 테이블이 있습니다.
- DT1에는 Colm : A, B, C, E, H, I.이 있습니다.
- DT2는 colm을 가지고 있습니다 : A, B, C, D, E, F, G, H, I
Dt2 행을 DT1 행에 연결해야하지만 DT1과 일치하는 열만 연결해야합니다. DT2에서 D, F, G를 구하십시오.
도움에 미리 감사드립니다.
(더 좋은 방법이 있다면, 누군가 그것을 게시하십시오!)
JMP 메뉴를 통해이 작업을 수행하는 경우 공통 열로 하위 집합을 만들고 하위 집합을 연결하십시오. JSL을 사용하여이를 자동화하려면 다음과 같이하십시오.
dt1 = New Table( "Untitled 6", invisible,
New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 4] ) ),
New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 6] ) ),
New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7, 8] ) )
);
dt2 = New Table( "Untitled 7", invisible,
New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [9, 10] ) ),
New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 12] ) ),
New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [13, 14] ) ),
New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [15, 16] ) )
);
// find column names common to both tables
names1 = dt1 << getcolumnnames( "string" ); // {"a", "b", "c", "d"}
names2 = dt2 << getcolumnnames( "string" ); // {"b", "c", "d", "e"}
// associative arrays offer a nice intersection method
set1 = Associative Array( names1 ); // ["a" => 1, "b" => 1, "c" => 1, "d" => 1, => 0]
set2 = Associative Array( names2 ); // ["b" => 1, "c" => 1, "d" => 1, "e" => 1, => 0]
common = set1; // make a copy; <<INTERSECT updates="" the="" left-hand-side="" common=""><< intersect( set2 ); // common==["b" => 1, "c" => 1, "d" => 1, => 0]
commonnames = common << getkeys; // {"b", "c", "d"}
// make subsets by selecting columns
dt1s = dt1 << Subset( All rows, columns( commonnames ), linked );
dt2s = dt2 << Subset( All rows, columns( commonnames ), linked );
// do the concatenation; tweak the extra parameters as needed
dt = dt1s << Concatenate( dt2s, Output Table( "ConcatTable" ), Create source column );
// clean up the intermediate tables
close(dt1s,nosave);
close(dt2s,nosave);
close(dt1,nosave);
close(dt2,nosave);
</INTERSECT>
Concatenated common columns연결된 공통 열
업데이트 : 링크 된 효율성을 위해 키워드를 << 하위 집합으로 변환합니다.