行列の列でモードを見つけるこんにちは!
いくつかの行列で最も一般的な値を見つけるためのスクリプトを書くための手助けが必要です。私は何百行ものデータテーブルを持っています。各行にはシーケンス列(ABCDABCDなど)があり、そのシーケンス内の特定の文字の位置を示す列を作成しました(たとえば、Aの位置は[1,5,0,0]です)。
(私はスクリプトを書くのがかなり新しいので、その文字を含む位置がこれ以上ない場合、今私のマトリックスは0をリストしています。文字列内の複数の位置を見つけるための明白で、より効率的な方法があるならば、私に知らせてください。そうでなければ、モードの1つとして0を除外する方法はありますか?)
私は今、すべての行で呼び出されたすべての位置を調べて、最も一般的な位置を見つけたいと思います。
私が持っているもの:
行マトリックス列
1 [2、3、6、8、0、0]
2 [2、4、5、10、0、0]
3 [2、7、9、10、0、0]
私が欲しいもの:
出現回数が多い順にモードを表示するリスト
位置2 - 3
位置10 - 2のオカレンス
私は現在持っている位置発見式を含むスクリプトを添付しました、
ありがとうございました!
再:行列の列でモードを見つけるありがとうございました!!再:行列の列でモードを見つけるdt << select where(:( letter == "A"&:行番号== 1)|(:Letter == "C"&:行番号== 2);
それはあなたにあなたの最初の要件を与えませんか?
私があなたが望むものを正しく理解していれば、あなたの2番目の要件はTabulateを使って計算できるはずです。
再:行列の列でモードを見つける行ごとに異なる文字の位置を特定してから、行を比較できるようにする必要があります。たとえば、1行目のシーケンスのすべての "A"の位置と、2行目のシーケンスの "C"のすべての位置を見つける必要があります。それから私はテーブルで最も頻繁に発生する場所を見ることができる必要があります。
あなたが私に与えたスクリプトから(ところでところでありがとう)私はまだこの表全体の比較をすることができない。
再:行列の列でモードを見つけるこれは、別の方法を使用して、すべてのLetter値を新しい列に解析し、そこから分析を実行できるようにするスクリプトです。
dt=current data table();
// Create a new table with just the Sequence column in it
dtbuild = dt << subset(columns("Sequence"), selected rows(0));
// Find the longest sequence
Maxstring = col max(length(:sequence));
// Add a new column called Row Num that will let you keep track of what row
// each letter came from
dtBuild << New column("Row Num", formula(row()));
// Convert the data into real values
dtBuild:Row Num << delete property("formula");
// Create a new column for each possible position in the sequence number, and
// strip off the ith character and place it into the column
For(i=1,i<=Maxstring,i++,
dtBuild << new column("C" || char(i),character, formula(substr(:sequence,eval(i),1)));
column(dtBuild,i) << delete property("formula");
);
// Create a list of the columns in the dtBuild data table
TheColumns = dtBuild << get column names();
// We are only going to stack the columns created that have bits of the
// sequence in them, so get rid of the names of the first 2 column in the data table
TheColumns = remove(TheColumns,1,2);
// Stack all of the columns in to a data table that can be worked with
dtFinal = dtBuild << Stack(
columns( TheColumns),
Source Label Column( "Position" ),
Stacked Data Column( "Letter" ),
Name( "Non-stacked columns" )(Keep( :Row Num ))
);
// Get rid of the interium table
close(dtBuild, nosave);
// Delete rows that have no letter value
dtFinal << select where(:Letter == "");
dtFinal << delete rows;