删除单元格值你好,
我有一个类似的表,如下所示:
1. 表有数字列 x_1, x_2, x3, ...
2. 我想从 cols x_1, x_2, x_3, ... 的所有行中删除特定值,例如 8。 (所需的 O/P 表也如下所示。)
输入表
| A |
乙 |
C |
x_1 |
x_2 |
x_3 |
x_4 |
x_5 |
x_6 |
乙 |
| |
|
|
1 |
8 |
2 |
7 |
2 |
2 |
|
| |
|
|
2 |
8 |
8 |
8 |
8 |
8 |
|
| |
|
|
8 |
8 |
2 |
5 |
3 |
8 |
|
所需输出表
| A |
乙 |
C |
x_1 |
x_2 |
x_3 |
x_4 |
x_5 |
x_6 |
乙 |
| |
|
|
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() ??
);
回复:删除单元格值这是对之前脚本的一个很小的更改,它将执行您想要的操作
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] = .;回复:删除单元格值有趣的。我对这样的东西有稍微不同的需求。
假设我有 2 列 A 和 B。A 应该有日期/时间,B 有一个键值。我有一些行缺少日期/时间,但 B 列有一个键。
当日期/时间丢失时,如何删除键值。
回复:删除单元格值数据表下标也是一种选择,以防它对您的情况更快。
dt = open("$SAMPLE_DATA/Big Class.jmp");
r = loc(dt[0, 4]==61)
dt[r, 4] = .;回复:删除单元格值多谢!
我正在考虑使用循环来迭代访问行,然后更改它,但这是使用 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>
回复:删除单元格值您正在正确地处理问题,只是存在一些语法问题。以下是您的代码的工作版本
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 )] = .;
);