Re:匹配值並對其進行編碼這是解決第一個問題的一種方法。 我正在使用矩陣運算來嘗試減少您必須進行的比較次數,如果您向每行向下行進每個單元格的比較。 其他人可能有更好的方法來做到這一點:
Names Default To Here( 1 );
dt = New Table( "Example",
Add Rows( 2 ),
New Column( "Jan", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11111, 33333] ) ),
New Column( "Feb", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [22222, 33333] ) ),
New Column( "March", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11111, 44444] ) ),
New Column( "April", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11111, 55555] ) ),
New Column( "May", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11111, 11111] ) ),
New Column( "June", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [22222, 33333] ) ),
New Column( "July", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11111, 22222] ) ),
New Column( "August",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [22222, 11111] ),
Set Display Width( 51 )
)
);
For( k = 1, k <= N Rows( dt ), k++,
theRow = dt[k, 0];
compare = theRow[1];
theRow = theRow - compare;
theLoc = Loc( theRow );
theRow = theRow + 1;
For( i = 1, i <= N Rows( theLoc ), i++,
theRow[theLoc[i]] = 0
);
theRow[1] = compare;
dt[k, 0] = theRow;
);
關於你的第二個問題......我對你所談論的內容感到有些困惑。 您能否展示一個簡單的示例,說明您現在的數據是什麼樣的,以及您希望它最終成為什麼樣的?
Re:匹配值並對其進行編碼歡迎 @ Apurva14
看看這個解決方案。
如果方向正確,請告訴我們
New Table( "Untitled",
Add Rows( 4 ),
New Column( "Jan",
Set Values( [11111, 33333, 44444, 55555] )
),
New Column( "Feb ",
Set Values( [22222, 33333, 11111, 55555] )
),
New Column( "March",
Set Values( [11111, 44444, 22222, 11111] )
),
New Column( "April ",
Set Values( [11111, 55555, 33333, 33333] )
),
New Column( "May ",
Set Values( [11111, 11111, 44444, 55555] )
),
New Column( "June",
Set Values( [22222, 33333, 44444, 55555] )
),
New Column( "July ",
Set Values( [11111, 22222, 22211, 55555] )
),
New Column( "August",
Set Values( [22222, 1111, 44444, 22222] )
)
);
// here is where the work starts
dt = Current Data Table();
cols = dt << get column names( string );
ncols = N Items( cols );
For( i = 1, i <= ncols, i++,
Eval( Parse( "dt << new column (cols[i+1], Formula(" || Char( cols[1] ) || " ==" || Char( cols[i + 1] ) ) )
);
最好,
羅恩
Re:匹配值並對其進行編碼關於你的第二個問題,請嘗試以下方法:
New Table( "Untitled",
Add Rows( 4 ),
New Column( "Jan", Set Values( [11111, 33333, 44444, 55555] ) ),
New Column( "Feb ", Set Values( [22222, 33333, 11111, 55555] ) ),
New Column( "March", Set Values( [11111, 44444, 22222, 11111] ) ),
New Column( "April ", Set Values( [11111, 55555, 33333, 33333] ) ),
New Column( "May ", Set Values( [11111, 11111, 44444, 55555] ) ),
New Column( "June", Set Values( [22222, 33333, 44444, 55555] ) ),
New Column( "July ", Set Values( [11111, 22222, 22211, 55555] ) ),
New Column( "August", Set Values( [22222, 1111, 44444, 22222] ) )
);
// here is where the work starts
dt = Current Data Table();
dt2 = dt << Stack(
columns( :Jan, :Feb, :March, :April, :May, :June, :July, :August ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
dt3 = dt2 << Summary(
Group( :Data ),
Freq( "None" ),
Weight( "None" )
);
dt2 << Update(
With( dt3 ),
Match Columns( :Data = :Data )
);
dt3 << close window (no save);
dt2 << Sort( By( :N Rows ), Order( Ascending ) , replace table);
// at this point the unique values should be at the top of the table
最好,
羅恩
匹配值並對其進行編碼因此,我在多個列中有多個相同的值(例如; -12345),我希望將第一列中的值保留為數字,並將其餘值(如果存在或不存在)編碼為0和1。
關於我所擁有的數據的另一件事是,有些值是唯一的,但它們不在第一列中,它們如何將它們堆疊在彼此之上並仍按月編碼。
這就是我的數據
1月2月3月4月5月6月7月8111 22222 11111 11111 11111 22222 11111 22222 33333 33333 44444 55555 11111 33333 22222 1111,等等等
比如說
111111 0 1 1 0 1 0我希望它看起來像這些!!
@staff感謝任何幫助