Come adattare i dati in un elenco standard di colonne?Ho una serie di colonne standard che vorrei utilizzare per più tabelle di dati, il problema è che alcune tabelle di dati potrebbero non contenere TUTTE quelle colonne.
Come posso semplicemente:
1. Creare una tabella dati con l'elenco di colonne standard (es: ES1, ES2, ES3, ES4, ES5)
2. Leggere una tabella di dati che può contenere parti delle colonne precedenti (es: ES1, ES3)
| | ES1 | ES3 |
| Conta la linea 1 | 2 | 4 |
| Conta la linea 2 | 2 | 10 |
3. Crea la tabella di dati del conteggio della tabella di dati n. 2 con l'elenco completo di colonne standard:
| | ES1 | ES2 | ES3 | ES4 | ES5 |
| Conta la linea 1 | 2 | 0 | 4 | 0 | 0 |
| Conta la linea 2 | 2 | 0 | 10 | 0 | 0 |
Ri: Come adattare i dati in un elenco standard di colonne?Qui ci sono un paio di modi per farlo
Names Default To Here( 1 );
dt1 = Data Table( "Your first table" );
dt2 = Data Table( "Your second table" );
dt1 << concatenate( dt2 );
Names Default To Here( 1 );
StdNamesList = {"PQrz", "acgh","bddxy","abcd"};
ExistingColNames = dt << get column names;
dt2 = Data Table( "Your second table" );
// If a std name exits in the data table, eliminate it from this working copy of the
// translate data table
For(i=1,i<=ncols(dt),i++,
If(contains(StdNamesList,ExistingColNames[i])
stdNamesList = remove( stdNamesList,contains(StdNamesList,ExistingColNames[i], 1))
)
);
// Add in the missing columns
For(i=1,i<=ncols(dt),i++,
dt2 << New Column(StdNamesList[i],set each value(0));
);Ri: Come adattare i dati in un elenco standard di colonne?Ciao Jim,
Il concatenato non sembra riassumere i valori delle righe comuni, ad esempio, per NDP1007, anticiperei il valore di ES3 ora 7 (la somma totale di Foglio 1, Foglio 1 2).
C'è un modo su cui posso fare questo?
Cordiali saluti,
Zach

Ri: Come adattare i dati in un elenco standard di colonne?Qualche idea su come riassumere due tabelle separate come ho indicato sopra?
Cordiali saluti,
ZachRi: Come adattare i dati in un elenco standard di colonne?Date le nuove specifiche, il problema diventa un po 'più complesso. Non c'è una funzione di sommatoria integrata in JMP. Ci sono così tante diverse azioni che si potrebbero voler fare con l'unione dei dati, la sommatoria non è impostata come l'elemento predefinito da fare. Lo script semplice sotto esegue la somma che desideri. La maggior parte del codice mostrato è solo lì per creare le tabelle di dati di esempio. Solo il codice nelle righe 32-59 fa il lavoro di mettere insieme i dati.
Names Default To Here( 1 );
// Create the sample data tables
dt = New Table( "Primary",
Add Rows( 3 ),
New Column( "Column 1",
Character,
"Nominal",
Set Selected,
Set Values( {"NDP1007", "NDP2024", "NDP3030"} )
),
New Column( "ES1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 2, 1] ) ),
New Column( "ES2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [5, 0, 1] ) ),
New Column( "ES3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [5, 0, 2] ),
Set Display Width( 46 )
),
New Column( "ES4", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 1, 3] ) ),
New Column( "ES5", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 2, 3] ) ),
Set Row States( [0, 1, 0] )
);
dt2 = New Table( "Secondary",
Add Rows( 2 ),
New Column( "Column 1", Character, "Nominal", Set Values( {"NDP1007", "NDP2024"} ) ),
New Column( "ES1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 0] ) ),
New Column( "ES3", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 3] ) )
);
// Change the names in the Secondary data table so after joining they can be summed together
// and create a list of the new names
newColNameList = {};
For( i = 2, i <= N Cols( dt2 ), i++,
Column( dt2, i ) << set name( (Column( dt2, i ) << get name) || "_X" );
Insert Into( NewColNameList, Column( dt2, i ) << get name );
);
// Update the primary data table with the secondary table
dt << Update( With( dt2 ), Match Columns( :Column 1 = :Column 1 ) );
// Create the code to add the data together that needs to be summed
For( col = 1, col <= N Items( newColNameList ), col++,
// Make sure the standard name is in the data table and if so, add
// the values together
If( Try( Column( dt, Word( -2, newColNameList[col], "_" ) ) << get name ) != "",
For( theRow = 1, theRow <= N Rows( dt ), theRow++,
Column( dt, Word( -2, newColNameList[col], "_" ) )[theRow] = Sum(
Column( dt, Word( -2, newColNameList[col], "_" ) )[theRow],
Column( dt, newColNameList[col] )[theRow]
)
)
)
);
// Delete the Secondary column no longer needed
dt << delete columns( newColNameList );Ri: Come adattare i dati in un elenco standard di colonne? @ zjuv007 ,
Jim, @txnelson , a condizione che tu abbia le chiavi per combinare i tuoi tavoli. L'ultimo passaggio per ottenere la somma dei record comuni è eseguire un sommario di tabella.
Lo script qui sotto si basa sulla prima soluzione di Jim e presuppone che si desideri la somma () di tutte le colonne numeriche. È possibile modificare numclist in modo che sia un elenco di possibili colonne, come dimostrato dal secondo script di Jim. Lo script e le tabelle di dati, sheet1 e sheet2, sono allegati.
Names Default To Here( 1 );
dt1 = Data Table( "sheet1" );
dt2 = Data Table( "sheet2" );
dt3 = dt1 << concatenate( dt2 );
numclist = dt1 << Get Column Names(Numeric, String);
sumXP = Expr(Summary(
Group( :Column 1 ),
Weight( "None" ),
statistics column name format( "column" ),
Link to original data table( 0 ),
Output Table Name ("Summed Table")
) );
for(i=1, i<=nitems(numclist), i++,
Insert Into(sumXP, EvalExpr(Sum(Column(Expr(numclist[i])))))
);
show(NameExpr(sumXP) );
Eval (EvalExpr(dt3 << expr(sumXP) ) );
dt = Data Table( "Summed Table" );
//option
dt << delete column( {"N Rows"});

Ri: Come adattare i dati in un elenco standard di colonne?Se voglio espandere questo per sommare le tabelle N, c'è un modo semplice per risolvere Sum2Tables.jsl per eseguire questo? (Nella maggior parte dei casi, lo limiterei a N = 5).
Cordiali saluti, ha funzionato!Ri: Come adattare i dati in un elenco standard di colonne?Inoltre, se mi piacerebbe semplicemente generare un elenco standard di queste colonne, nelle istanze in cui la prima tabella che afferro non ha tutte le colonne appropriate ... Posso farlo prima, quindi semplicemente compilare e contare come zeri dove non ci sono conteggi in quella specifica colonna di somma?Ri: Come adattare i dati in un elenco standard di colonne?Prima di fare queste domande, è necessario studiare la risposta fornita, in modo da capire come funziona. Se capisci la dichiarazione
dt3 = dt1 << concatenate( dt2 );
e cercalo nella Guida allo scripting, oppure nell'indice Scripting, vedrai che puoi concatenare insieme tante tabelle di dati in un'unica istruzione come desideri.
Per quanto riguarda la tua seconda domanda, cambiare la linea
numclist = dt1 << Get Column Names(Numeric, String);
a
numclist = dt3 << Get Column Names(Numeric, String);
ti fornirà un elenco completo di tutte le colonne trovate in tutte le tabelle di dati. Usare quella lista combinata potrebbe essere la risposta che ti serve