Colorea las celdas para los valores que no aparecen más en cada fila.Hola a todos,
He estado luchando para armar algo que funcione para esto.
Me gustaría iterar sobre cada fila y colorear las celdas cuyo valor NO aparezca más. Por ejemplo, usando la siguiente tabla:
| | RowNames | Tienda1 | Tienda2 | Tienda3 | Tienda4 | Tienda5 |
| 1 | Animal | Gato | Perro | Gato | Gato | Pájaro |
| 2 | Costo | 10 | 12 | 8 | 10 | 6 |
Fila 1: resaltar perro y pájaro
Fila 2: resaltar 12, 8 y 6
¡Gracias!
Re: celdas de color para los valores que no aparecen más en cada fila¡Gracias! Esto funciona muy bien!Re: celdas de color para los valores que no aparecen más en cada filaBuen enfoque!
Veo un problema, y si hay más de una selección ... digamos, tanto el Gato como el Perro tienen el mismo número de ocurrencias ...
Es por eso que hice la división y la combinación de columnas ......
Re: celdas de color para los valores que no aparecen más en cada filaProblema interesante. Intenté un enfoque diferente utilizando la transposición, que me permite usar operaciones de columna.
dt = New Table( "example",
Add Rows( 2 ),
New Column( "RowNames", Character( 16 ), "Nominal", Set Values( {"Animal", "Cost"} ) ),
New Column( "Store1", Character( 16 ), "Nominal", Set Values( {"Cat", "10"} ) ),
New Column( "Store2", Character( 16 ), "Nominal", Set Values( {"Dog", "12"} ) ),
New Column( "Store3", Character( 16 ), "Nominal", Set Values( {"Cat", "8"} ) ),
New Column( "Store4", Character( 16 ), "Nominal", Set Values( {"Cat", "10"} ) ),
New Column( "Store5", Character( 16 ), "Nominal", Set Values( {"Bird", "6"} ) )
);
dtt = dt << Transpose(
columns( :Store1, :Store2, :Store3, :Store4, :Store5 ),
Label( :RowNames ),
Output Table( "Transpose of example" ),
invisible
);
for (i = 1, i <= nrows(dt), i++,
one_col = column(dt, "RowNames")[i];
tab = dtt << Tabulate(
Show Control Panel( 0 ),
Add Table( Row Table( Grouping Columns( column(dtt, one_col) ) ) ),
invisible
);
dtb = tab << Make Into Data Table;
dtb << sort(by(:N), replace table(1));
nr = nrows(dtb);
// Get the maximum counted value
max_value = column(dtb, one_col)[nr];
// Now back to the original table - highlight everything but the max value
for (k = 2, k <= ncols(dt), k++,
one_value = column(dt, k)[i];
if (one_value != max_value,
column(dt, k) << Color Cells( "Light Yellow", i );
);
);
close(dtb, nosave);
);
close(dtt, nosave);
Re: celdas de color para los valores que no aparecen más en cada filaAquí hay un script que funciona para su tabla de datos de ejemplo, y con un poco de trabajo, debería funcionar para cualquier tabla con la que necesite trabajar.
Names Default To Here( 1 );
dt = New Table( "example",
Add Rows( 2 ),
New Column( "RowNames", Character( 16 ), "Nominal", Set Values( {"Animal", "Cost"} ) ),
New Column( "Store1", Character( 16 ), "Nominal", Set Values( {"Cat", "10"} ) ),
New Column( "Store2", Character( 16 ), "Nominal", Set Values( {"Dog", "12"} ) ),
New Column( "Store3", Character( 16 ), "Nominal", Set Values( {"Cat", "8"} ) ),
New Column( "Store4", Character( 16 ), "Nominal", Set Values( {"Cat", "10"} ) ),
New Column( "Store5", Character( 16 ), "Nominal", Set Values( {"Bird", "6"} ) )
);
// Add a new column to use as a pointer to the row
dt << New Column( "TheRow", formula( Row() ) );
// Convert to static values for TheRow
dt:TheRow << delete formula;
// Stack the columns in question, so the processing can be done all at once
dtStack = dt << Stack(
columns( :Store1, :Store2, :Store3, :Store4, :Store5 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Name( "Non-stacked columns" )(Keep( :TheRow ))
);
// Summarize the data to find the max count for each row values
dtSum = dtStack << Summary(
Group( :TheRow, :Data ),
Freq( "None" ),
Weight( "None" ),
Link to Original Data Table( 0 )
);
Close( dtStack, nosave );
// Add a new column to represent the maximums
dtSum << New Column( "TheMax",
formula( If( :N Rows == Col Maximum( :N Rows, :TheRow ), 1, 0 ) )
);
// Delete the non max rows in the table
dtSum << select where( :TheMax == 0 );
dtSum << delete rows;
// Create a new table that has only one row for each row in the original data table
// and has a column for each maximum value found
dtSplit = dtSum << Split(
Split By( :Data ),
Split( :Data ),
Group( :TheRow ),
Remaining Columns( Drop All ),
Sort by Column Property
);
Close( dtSum, nosave );
// Add a column that concatenates all values into one
theColumns = dtSplit << get column names;
theColumns = Remove( theColumns, 1, 1 );
dtSplit << Combine Columns(
delimiter( "," ),
Columns( Eval( theColumns ) ),
Column Name( "The Maximums" )
);
// Delete the nonessential columns
dtSplit << delete columns( theColumns );
// attach the found maximumns to the original data table
dt = dt << Update( With( dtSplit ), Match Columns( :TheRow = :TheRow ) );
Close( dtSplit, nosave );
// Color the cells
For( i = 1, i <= N Rows( dt ), i++,
theList = As List( Words( dt:The Maximums[i], "," ) );
If( N Rows( Loc( theList, dt:Store1[i] ) ) == 0,
dt:Store1 << Color Cells( "Red", i )
);
If( N Rows( Loc( theList, dt:Store2[i] ) ) == 0,
dt:Store2 << Color Cells( "Red", i )
);
If( N Rows( Loc( theList, dt:Store3[i] ) ) == 0,
dt:Store3 << Color Cells( "Red", i )
);
If( N Rows( Loc( theList, dt:Store4[i] ) ) == 0,
dt:Store4 << Color Cells( "Red", i )
);
If( N Rows( Loc( theList, dt:Store5[i] ) ) == 0,
dt:Store5 << Color Cells( "Red", i )
);
);
// Cleanup
dt << delete columns( {"TheRow", "The Maximums"} );