重複した列を削除こんにちは:
400以上の列と5万行のhugueデータテーブルがあります。重複した列が30〜40あり、それらをデータテーブルから削除します。何か案は?
再:重複した列を削除意図された用途に「良い」かもしれないし、そうでないかもしれないブルートフォース(そして未試験)の代替手段は以下の通りです:
NamesDefaultToHere(1);
dt = CurrentDataTable();
// Make a matrix 'mat' holding pairwise equality of column values
n = NCol(dt);
mat = J(n, n, .);
for(c1 = 1, c1 <=n, c1++,
for(c2 = c1+1, c2 <= n, c2++,
c1Vals = Column(dt, c1) << getValues;
c2Vals = Column(dt, c2) << getValues;
mat[c1, c2] = all(c1Vals == c2Vals);
);
);
// Convert 'mat' to a table
cols = dt << getColumnNames("String");
dtn = dt << getName;
dt2 = AsTable(mat, << columnNames(cols));
dt2 << setName("Duplicate Columns in "||dtn);
dt2 << NewColumn("Column", Character, Values(cols));
dt2 << moveSelectedColumns({"Column"}, ToFirst);再:重複した列を削除あなたが使用することができます MD5チェックサム 、によって生成されたブロブMD5() 列内の値のハッシュを生成してから、列間でチェックサムを比較する関数。
連想配列を使用すると、重複するmd5チェックサムが生成されたときにそれらをチェックして、すべてのチェックサムと他のすべてのチェックサムを自分で比較する手間を省くことができます。
dt = New Table( "Some Duplicate Columns",
Add Rows( 1000 ),
New Column( "Column 1", Numeric, "Continuous", Format( "Best", 12 ), Formula( Random Normal() ) ),
New Column( "Copy of Column 1", Numeric, "Continuous", Format( "Best", 12 ), Formula( :Column 1 ) ),
New Column( "Not a copy of Column 1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( If( Row() == 1, 1, :Column 1 ) )
),
New Column( "Character copy of Column 1", Character, "Nominal", Formula( Char( :Column 1 ) ) ),
New Column( "Character copy of Copy of Column 1",
Character,
"Nominal",
Formula( Char( :Copy of Column 1 ) ),
)
);
//get values into matrix (numeric columns) or list (character columns)
c1 = :column 1 << get values;
c2 = :Copy of Column 1 << get values;
//avoid having to check column data types when converting the values to blob
//by converting matrix or list to character
//
//if you're not lazy you could use the Matrix to Blob() function for numeric columns
//and the Char to Blob() function for character columns
char_c1 = Char( c1 );
char_c2 = Char( c2 );
c1_md5 = Blob MD5( Char To Blob( char_c1 ) );
c2_md5 = Blob MD5( Char To Blob( char_c2 ) );
Show( c1_md5 == c2_md5 );
//check the whole data table using hex version of md5 as keys of associative array
aa = Associative Array();
For( i = 1, i <= N Col( dt ), i++,
md5 = Hex( Blob MD5( Char To Blob( Char( Column( dt, i ) << get values ) ) ) );
//check to see if the associate array already has a key named with this md5
If( aa << Contains( md5 ),
//aa does contain md5
Print( aa[md5] || " is a duplicate of " || (Column( dt, i ) << get name) ),
//aa does not contain md5
//store a key named with this md5 with a value of the column name
aa[md5] = Column( dt, i ) << get name;
);
);
再:重複した列を削除重複列が非常に多いのはなぜですか。これを防ぐことはできますか?
再:重複した列を削除こんにちは、
私は今日同じ問題に遭遇します、そしてここに私のスクリプトは重複した列を削除することです。
数千行を超えるテーブルがあると、本当に時間がかかります。それを実行するためのより効率的な方法があるはずです。誰かがそれを見つけ出して共有できることを願います。
Names Default To Here( 1 );
col_name = dt << get column names;
dup_col = {}; //store the duplicated column name
same_c = 0; //to record how many rows are the same while doing columns comparison
/* When the elements are the same in the same row for 2 columns, same_c will be added by 1*/
/*If the same_c is equal to the total row number, then the 2 columns are the same. Insert the column name into dup_col*/
For( i = 1, i <= (N Cols( dt ) - 1), i++,
For( k = i + 1, k <= N Cols( dt ), k++,
(For Each Row( If( :(col_name[i])[Row()] == :(col_name[k])[Row()], same_c++, Wait( 0 ) ) ) ;
If( same_c == N Rows( dt ), Insert Into( dup_col, col_name[k] ), Wait( 0 )) ;
same_c = 0 ; )
)
);
dt << Delete Column( Eval( dup_col ) );
// delete the duplicated columns
再:重複した列を削除私はこれを行うための組み込みのJMPメソッドを知りません。 ただし、列が同一かどうかを判断するためにRSquare統計を使用できます。
あなたがこれを対話的にやろうとしているなら、連続的な列は以下を使って識別されることができます。
分析==>多変量法==>多変量
それはあなたがデータテーブルに出力することができますそしてそれからどの列が1の相関を持っているかを識別するためにそれを使用することができる相関行列をあなたに与えるでしょう。
序数/名目上の列は、Fit Y by XのRSquareテーブルから "Make Combined Data Table"を作成することによって識別できます。もう一度、1.0のRSquareは列が同一であるという手がかりを与えます。
今、あなたがソリューションをスクリプト化するつもりなら、上記はかなり簡単に自動化することができます。
たぶん他のコミュニティメンバーがより良い解決策を持つでしょう