Come faccio a moltiplicare due tabelle insiemeHo una tabella di big data e una tabella dei fattori di normalizzazione.
La tabella dei dati ha questo aspetto:
| ID | genere | parametro1 | parametro2 | parametro3 |
| 01 | 1 | dati | dati | dati |
| 02 | 1 | dati | dati | dati |
| 03 | 2 | dati | dati | dati |
| 04 | 2 | dati | dati | dati |
La tabella dei fattori di normalizzazione ha questo aspetto:
| genere | parametro1 | parametro2 | parametro3 |
| 1 | fattore di normalizzazione 1 | fattore di normalizzazione 2 | fattore di normalizzazione 3 |
| 2 | fattore di normalizzazione 4 | fattore di normalizzazione 5 | fattore di normalizzazione 6 |
Come posso moltiplicare la prima tabella per la seconda tabella in base al tipo e al parametro e ottenere una nuova tabella come questa:
| ID | genere | parametro1 | parametro2 | parametro3 |
| 01 | 1 | dati * fattore di normalizzazione 1 | dati * fattore di normalizzazione 2 | dati * fattore di normalizzazione 3 |
| 02 | 1 | dati * fattore di normalizzazione 1 | dati * fattore di normalizzazione 2 | dati * fattore di normalizzazione 3 |
| 03 | 2 | dati * fattore di normalizzazione 4 | dati * fattore di normalizzazione 5 | dati * fattore di normalizzazione 6 |
| 04 | 2 | dati * fattore di normalizzazione 4 | dati * fattore di normalizzazione 5 | dati * fattore di normalizzazione 6 |
La mia tabella di dati grezzi è enorme sia nelle righe che nelle colonne, quindi voglio una soluzione rapida.
Grazie mille.
Tabella datiScriptingRi: Come faccio a moltiplicare due tabelle insiemePotresti usare un join virtuale e colonne formula.
Virtual join aggiunge le chiavi blu e oro
Puoi collegarli in modo interattivo o con JSL.
Questo potrebbe utilizzare nomi JMP16 con l'estensione : "parametro3 [Tipo]" n sintassi; potresti aver bisogno del nome ( "parametro3 [Tipo]" ) anziché.
// make example tables. **save them** so virtual join works.
factorDT = New Table( "Imported Data 2",
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 1.2] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0.8, 0.9] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 0.9] ) )
);
factorDT << save( "$temp/factor.jmp" );
dataDT = New Table( "Imported Data",
New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 1, 2, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 3, 2, 1] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 3, 2] ) )
);
dataDT << save( "$temp/data.jmp" );
// join the tables
factorDT:type << Set Property( "Link ID", 1 );
dataDT:type << Set Property( "Link Reference", Reference Table( "factor.jmp" ) );
// add formula columns
dataDT << New Column( "p 1", Numeric, "Continuous", Format( "Best", 12 ), Formula( :"parameter1[Type]"n * :parameter1 ) );
dataDT << New Column( "p 2", Numeric, "Continuous", Format( "Best", 12 ), Formula( :"parameter2[Type]"n * :parameter2 ) );
dataDT << New Column( "p 3", Numeric, "Continuous", Format( "Best", 12 ), Formula( :"parameter3[Type]"n * :parameter3 ) );
// force the evaluation to complete
dataDT<<RUNFORMULAS></RUNFORMULAS>
Ri: Come faccio a moltiplicare due tabelle insiemeE se non hai bisogno delle formule, potresti prendere in considerazione la moltiplicazione degli elementi delle matrici che può o non può essere "migliore". Sul mio MacBook il codice seguente ha richiesto circa 15 secondi.
NamesDefaultToHere(1);
nr = 10000; // Number of rows
nc = 10000; // Number of Columns
dt1 = AsTable(J(nr, nc, RandomInteger(1, 20)));
dt2 = AsTable(J(nr, nc, RandomUniform(0, 1)));
m1 = dt1 << getAsMatrix;
m2 = dt2 << getAsMatrix;
dtFinal = AsTable(m1 :*</img> m2);
Ri: Come faccio a moltiplicare due tabelle insiemeGrazie per la risposta. Tuttavia, ho molte colonne e i nomi delle colonne sono complicati. Quindi voglio scrivere un ciclo for per creare nuove colonne. Puoi spiegare di più su questa affermazione?
Formula( :"parameter1[Type]"n * :parameter1 )
Sto pensando di scrivere un ciclo for come questo:
</CODE></PRE><PRE class="lia-code-sample language-markup"><CODE>colnames = dataDT << Get Column Names();
nc = ncols(dataDT);
DT = New Table("normalized", New Column("ID", values(dataDT:ID << get values)),
New Column("Type", values(dataDT:Type << get values)));
For(i = 3, i<= nc, i++,
DT << New Column( char( colnames[3]), Numeric, "Continuous", Format( "Best", 12 ), Formula( XXXX ) ));Ma non so come costruire correttamente la formula . Continua a darmi errori. Mi potete aiutare?
Grazie.
Ri: Come faccio a moltiplicare due tabelle insiemeGrazie, funziona su un piccolo set di dati. Ma ho milioni di righe nella tabella 1 e solo due righe nella tabella 2. Quindi voglio evitare di creare un altro enorme tavolo. Se non riesco a trovare una soluzione migliore, proverò questo metodo.
Ri: Come faccio a moltiplicare due tabelle insiemeIl giro non è facile; Penso che questo lo farà:
// make example tables. **save them** so virtual join works.
factorDT = New Table( "Imported Data 2",
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 1.2] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0.8, 0.9] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1.1, 0.9] ) )
);
factorDT << save( "$temp/factor.jmp" );
dataDT = New Table( "Imported Data",
New Column( "ID", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "Type", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 1, 2, 2] ) ),
New Column( "parameter1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2, 3, 4] ) ),
New Column( "parameter2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 3, 2, 1] ) ),
New Column( "parameter3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3, 3, 2] ) )
);
dataDT << save( "$temp/data.jmp" );
originalColumns = dataDT<<GETCOLUMNNAMES></GETCOLUMNNAMES>
- catturare le colonne originali prima di aggiungere le colonne nascoste con join virtuale
- crea l'espressione e usando \! "per evitare le virgolette incorporate
- usa write () per eseguire il debug del tuo lavoro, non print
- << RunFormulas è importante per la velocità; la valutazione in background predefinita delle formule di colonna è molto più lenta