セル値の削除こんにちは、
以下に示すような同様のテーブルがあります。
1. テーブルには数値列 x_1、x_2、x3、... があります。
2. 列 x_1、x_2、x_3、... のすべての行から特定の値、たとえば 8 を削除したいと考えています。 (以下に示す必須の O/P テーブルも同様です。)
入力テーブル
| あ |
B |
C |
x_1 |
x_2 |
x_3 |
x_4 |
x_5 |
x_6 |
E |
| |
|
|
1 |
8 |
2 |
7 |
2 |
2 |
|
| |
|
|
2 |
8 |
8 |
8 |
8 |
8 |
|
| |
|
|
8 |
8 |
2 |
5 |
3 |
8 |
|
必要な出力テーブル
| あ |
B |
C |
x_1 |
x_2 |
x_3 |
x_4 |
x_5 |
x_6 |
E |
| |
|
|
1 |
。 |
2 |
7 |
2 |
2 |
|
| |
|
|
2 |
。 |
。 |
。 |
。 |
。 |
|
| |
|
|
。 |
。 |
2 |
5 |
3 |
。 |
|
私のスクリプトが添付されています...
ヘルプ/フィードバックをよろしくお願いします:)
dt = Current Data Table ();
for (i=1, i<=6, i++, //iterate through columns loop
temp = "x_" || char (i); //column name
dt << Go To (temp); //select column
dt << Select Where (temp==8);// Select rows where value is 8 ***PROBLEM*** Not selecting rows :(
//After selecting rows where value is 8 for a specific column, I want to delect the value...May be use Empty() ??
);
Re: セル値の削除これは、必要なことを実行する前のスクリプトへの非常に小さな変更です。
names default to here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
// set some height rows to missing
dt:height[6] = .;
dt:height[14] = .;
r = loc(ismissing(dt[0, 4]));
// set the values in column 5(wieght) to missing
// for the rows found(located) in column 4
dt[r, 5] = .;Re: セル値の削除面白い。私はこのようなものに対して少し異なるニーズを持っています。
A と B の 2 つの列があるとします。A には日付/時刻があり、B にはキー値があるはずです。日付/時刻が欠落している行がありますが、列 B にはキーがあります。
日付/時刻が欠落している場合にキー値を削除するにはどうすればよいですか。
Re: セル値の削除状況により高速な場合には、データ テーブルの添字付けもオプションです。
dt = open("$SAMPLE_DATA/Big Class.jmp");
r = loc(dt[0, 4]==61)
dt[r, 4] = .;Re: セル値の削除どうもありがとう!
ループを使用して行に反復的にアクセスして変更することを考えていましたが、これはJSLを使用する非常に良い方法です:)
<SPAN class="token function">Column</SPAN><SPAN class="token punctuation">(</SPAN> dt<SPAN class="token punctuation">,</SPAN> ColList<SPAN class="token punctuation">[</SPAN>i<SPAN class="token punctuation">]</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">[</SPAN>dt <SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN> get rows where<SPAN class="token punctuation">(</SPAN> <SPAN class="token function">As Column</SPAN><SPAN class="token punctuation">(</SPAN> dt<SPAN class="token punctuation">,</SPAN> ColList<SPAN class="token punctuation">[</SPAN>i<SPAN class="token punctuation">]</SPAN> <SPAN class="token punctuation">)</SPAN> <SPAN class="token operator">==</SPAN> <SPAN class="token number">8</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">]</SPAN> <SPAN class="token operator">=</SPAN> <SPAN class="token punctuation">.</SPAN><SPAN class="token punctuation">;</SPAN>
Re: セル値の削除あなたは問題に正しく取り組んでいますが、構文上の問題がいくつかあるだけです。以下はコードの動作バージョンです
Names Default To Here( 1 );
dt = Current Data Table();
// Select the columns to be evaluated
// ColList = {"x_1","x_2","x_3","x_4","x_5","x_6"};
// or if there is a programmatic way to get the list,
// do something like below
ColList = dt << get column names( numeric, string );
// Loop backwards through the list so the "i" index
// maintains it's proper reference
For( i = N Items( ColList ), i >= 1, i--,
If( Left( ColList[i], 2 ) != "x_",
ColList = Remove( ColList, i, 1 )
)
);
// Loop across ColList and set the values qualified
// values to missing
For( i = 1, i <= N Items( ColList ), i++,
// The line below takes advantage of a JMP feature where
// you can change specific values in a column in one statement
// by just using a matrix of the rows you want to change
// Column A[5,6,9,22] = 4;
// This would set a column named "Column A"'s rows 5,6,9 and 22
// to the value of 4
// In your case, you want to eliminate the cell value, so the
// line sets the value to a missing value, which in JMP is "."
Column( dt, ColList[i] )[dt << get rows where( As Column( dt, ColList[i] ) == 8 )] = .;
);