Avere due tabelle di dati.
- DT1 ha Colm: A, B, C, E, H, I.
- DT2 ha colm: A, B, C, D, E, F, G, H, I
Ho bisogno di concatenare le righe Dt2 alle righe di DT1 ma solo le colonne che corrispondono a DT1. Quindi non voglio colmi: D, F, G, da DT2.
Grazie in anticipo per l'aiuto.
(Se c'è un modo migliore, qualcuno pubblicarlo!)
Se lo fai attraverso i menu di JMP, crea sottoinsiemi con le colonne comuni e concatena i sottoinsiemi. Per automatizzarlo con JSL, qualcosa di simile.
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 columnsColonne comuni concatenate
Aggiornamento: aggiungere il connesso parola chiave al sottogruppo << per l'efficienza.