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感谢任何帮助