データ テーブルを変更して、0 に設定されている値をドットに変更するにはどうすればよいですか。ドットをゼロに変更するスクリプトは見つかりましたが、代替手段は見つかりませんでした。
ありがとう、
グッドタイミング。 私はちょうど先週、いくつかの関連コードに取り組んでいて、実行時間の短縮を行っていましたが、すでに述べたことに追加したいと考えていました。1 つのスクリプトで、行をループしてマトリックス メソッド (Vince が上記で参照) に置き換えることから、実行時間が約 20 倍から 25 倍改善されました。別のスクリプトでは、get rows where() から matrix メソッドに変更すると、ほぼ 2 倍改善されました。 私がそれをしている間に、後で共有または参照できるように以下のコードを書きました。ここに投稿するのが妥当だと思われます。 文字列のリストで Loc() を使用すると、異なる構文が使用され、数値列から取得するすべての行列変数でできるように、より複雑なロジックを構築できないことに注意してください。 そこで、クレイジ・ヘイルズが共有したテクニックを使用しました (ここにリンクされています) 連想配列と交差関数を使用します。 お役に立てば幸いです。
このスクリプトは新しい文字列を追加し、そこにコメントを入れることに注意してください。これは、デモ用に作成したためです。 ここで元の質問を考えると、次のような割り当て行を置き換えることができますc3[rowsMale] = "男性";とcolumn(dtData, "年齢") [行男性] = .;または類似。
names default to here(1);
dtData = Open( "$SAMPLE_DATA/Big Class.jmp" );
mAge = column(dtData, "age") << get values(); //a matrix
mHeight = column(dtData, "height") << get values(); //a matrix
lSex = column(dtData, "sex") << get values(); //a list
lName = column(dtData, "name") << get values(); //a list
<BR />//note the results of the Loc() function will return a matrix that corresponds to the rows that match the criteria<BR />
rowsTall = Loc(mHeight > 63); // simple comparison in Loc() function.
c1 = new column("Comments 1","Character");
c1[rowsTall] = "Tall";
rowsTallAndOver13 = Loc( (mHeight > 63) & (mAge > 13)); // can build more complex logic in Loc() function
c2 = new column("Comments 2","Character");
c2[rowsTallAndOver13] = "Tall and 14 or older";
rowsMale = Loc(lSex, "M"); // note syntax is slightly different with Loc() for lists when dealing with character columns.
//rowsMaleNamedRobert = Loc((lSex, "M"), (lName, "Robert")); // Cannot build complex comparisons with Character columns, see below on the intersection and AA's
c3 = new column("Comments 3","Character");
c3[rowsMale] = "Male";
//rowsTall17M = Loc((mHeight > 63) & (mAge == 17) & (lSex == "M") ); // attempt at building complex logic but the syntax is not correct, and can't have lists in a compound comparison
//rowsTall17M = Loc((mHeight > 63) & (mAge == 17) & (lSex, "M") ); // attempt at building complex logic. Syntax is closer to correct, but can't have lists in a compound comparison<BR />//Build numeric comparisons all at once, then do character comparisons one at a time. Only 1 character comparison shown here.
rowsTall17 = Loc((mHeight > 63) & (mAge == 17) ); // Build the numeric parts separate from char column(s)
rowsMale = Loc(lSex, "M"); // Character columns separately. Seems you need one variable per character column, and then intersect them all later.
<BR />//insert above into associative arrays, use intersection function to get the matrices intersection
aa_rowsTall17 = associative array(rowsTall17);
aa_rowsMale = associative array(rowsMale);
intersection = aa_rowsMale; // copy of aa_rowsMale, as intersection gets modified in next line
intersection<<INTERSECT> 63) );
c5 = new column("Comments 5 - using get rows where","Character");
c5[gRowsTallM17] = "Tall, Male, 17";</INTERSECT>
テーブル全体を実行しようとしている場合は、次のように実行できます
Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");
dt:weight[[1, 5, 6, 8]] = 0; // just setting them to 0
dt:height[[11, 15, 16, 18]] = 0;
wait(2);
// this is the bit you'll want
numeric_cols = dt << Get Column Names("Numeric", "string");
m = dt[0, numeric_cols]; // get the values as a matrix;
m[Loc(m==0)]=.; // set them to missing
dt[0, numeric_cols] = m; // set the data to the matrix「A」という名前の列について、すべての「0」を欠損値に変換する 1 つの方法を次に示します。
Names Default To Here( 1 );
dt = Current Data Table();
theRows = dt << get rows where( :A == 0 );
Try( :A[theRows] = . );
この投稿を見ることをお勧めしますデータ テーブルをループするか、Recode を使用するか、Get Rows Where を使用してデータ テーブルの値を変更する必要がありますか(そしてオリジナル役職)とそこでの議論。 私の記憶が正しければ、ポイントは 999 を欠損値に置き換えることでした。 基本的な考え方は、通常、行または列をループして値を置き換えることです。