안녕 모두,
나는 이것을 위해 노력하는 무언가를 모으기 위해 고심하고있다.
각 행을 반복하고 값이 가장 많이 표시되지 않는 셀의 색을 지정하고 싶습니다. 예를 들어 다음 표를 사용합니다.
| | RowNames | 상점 1 | Store2 | 상점 3 | 상점 4 | 상점 5 |
| 1 | 동물 | 고양이 | 개 | 고양이 | 고양이 | 새 |
| 2 | 비용 | 10 | 12 | 8 | 10 | 6 |
1 행 : 개와 버드 강조 표시
행 2 : 강조 표시 12, 8 및 6
감사!
좋은 접근!
나는 하나의 이슈를 보았습니다. 하나 이상의 선택이 있다면 ... 고양이와 개 모두 같은 숫자의 출현을 가지고 있다고 가정 해 봅시다 ...... ......
그래서 나는 쪼개지 며 열을 결합했다.
재미있는 문제. 나는 열 조작을 사용할 수있는 transpose를 사용하여 다른 접근법을 시도했다.
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);
다음은 예제 데이터 테이블에서 작동하는 스크립트입니다. 약간의 작업만으로도 작업에 필요한 모든 테이블에서 작동해야합니다.
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"} );