选择含有空数据的单元格我有一张如下表所示的表格:
| 操作员 |
M型 |
描述 |
说明2 |
M1 |
M2 |
M3 |
M4 |
M5 |
M6 |
| 第415章 |
Nxyz |
热的 |
热清洁1 |
第415章 |
第415章 |
第415章 |
第415章 |
第415章 |
第415章 |
| 615 |
Nxyz |
乙冷 |
冷清洁 1 |
615 |
615 |
615 |
|
615 |
615 |
| 815 |
Nxyz |
热的 |
热清洁2 |
815 |
815 |
815 |
815 |
815 |
815 |
| 1015 |
Nxyz |
乙冷 |
冷清洁2 |
1015 |
|
1015 |
1015 |
1015 |
1015 |
| 1215 |
Nxyz |
热的 |
热清洁1 |
1215 |
1215 |
1215 |
1215 |
1215 |
1215 |
| 1415 |
Nxyz |
乙冷 |
冷清洁 1 |
1415 |
1415 |
1415 |
1415 |
1415 |
|
| 1615 |
Nxyz |
热的 |
热清洁2 |
1615 |
1615 |
1615 |
1615 |
1615 |
1615 |
| 1815 |
Nxyz |
乙冷 |
冷清洁2 |
1815 |
1815 |
1815 |
|
|
1815 |
我只想选择空行。 由于每次提取数据时,M1-M6 列都会有所不同,因此我无法在 JSL 脚本中使用列名称。 我尝试使用下面的 FOR 循环来选择空数据行,但这只会选择最后一个单元格为空的行。
dt = Current Data Table();
nc = dt << get column names( Numeric );
For( i = 1, i <= N Items( nc ), i++,
dt <<SELECT where=""></SELECT>
最终我想让输出表如下所示
| 操作员 |
M型 |
描述 |
说明2 |
机器 |
| 615 |
Nxyz |
乙冷 |
冷清洁 1 |
M4 |
| 1015 |
Nxyz |
乙冷 |
冷清洁2 |
M2 |
| 1415 |
Nxyz |
乙冷 |
冷清洁 1 |
M6 |
| 1815 |
Nxyz |
乙冷 |
冷清洁2 |
M4 |
| 1815 |
Nxyz |
乙冷 |
冷清洁2 |
M5 |
这样做的最大技巧是在不编码(M1、M2 等...)的列名称的情况下执行此操作,因为它们将发生变化。
有任何想法吗
自动化和脚本编写回复:选择包含空数据的单元格<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />谢谢大家......除了 Loc Nonmissing 之外一切都有效......我目前只有 JMP9(懒得升级)并且该功能在 JMP9 中不起作用......我仍然JSL新手......再次感谢
回复:选择包含空数据的单元格MS 更灵活 - 现在让我们看看您如何用 0 行代码完成它!哈哈只是为了表明在 JSL 中有多种方法可以做同样的事情。
回复:选择包含空数据的单元格如果我正确地阅读您的消息,我认为您实际上有两个问题。
- 如何查找给定列集全部缺失的行。
- 如何使您的代码不依赖于这些列的名称及其数量。
毫不奇怪,有很多不同的方法可以做到 1。 PM罗兹,多发性硬化症和克雷格@JMP在那里给了你一些选择。
我再扔一张。 你可以使用缺失数据模式找到它们的实用程序。
dt = Open( "$SAMPLE_DATA\Cities.jmp" );
//delete some columns from this table to make it fit your example
dt << delete columns( "PM10", "X", "Y" );
//change name of data table to ensure this modified version doesn't get saved
//over the sample data
dt << set name( "CitiesModified" );
//I want to use the columns starting at column 9,
//so I build a list of references to them
mycols = {};
For( i = 9, i <= N Cols( dt ), i++,
Insert Into( mycols, Column( dt, i ) )
);
mdp = Dt << Missing Data Pattern( columns( Eval( mycols ) ), Output Table( "Missing Data Pattern" ) );
//The patterns columns shows the pattern of missing values
//the Missing Data Pattern data table is sorted,
//so if there are rows with all missing data
//the last row of the Missing Data Pattern data table will be all 1s.
//The Repeat() function just builds a string of 1s for as many columns as I'm working with
If( Column( mdp, "Patterns" )[N Rows( mdp )] == Repeat( "1", N Items( mycols ) ),
//The Missing Data Pattern data table is linked to the source table so selecting a row
//in it, selects all the rows that it represents in the source table
mdp << Select Rows( N Rows( mdp ) );
//now I can delete the rows in the source table
dt << delete rows;
,
Show( "No all missing rows" )
);
我试图展示如何使此代码适用于任意数量的列。 在本例中,因为我需要将列列表传递给缺失数据模式实用程序,所以我根据列号构建了一个列表。
即使已经编写了所有这些内容并展示了如何使用缺失数据模式实用程序,我认为我最喜欢的解决方案是PM罗兹的使用堆栈列。 无论如何,您确实希望最终得到堆积的数据,因此首先这样做可以轻松地选择堆积列中丢失的行并将其删除。
dt = Open( "$SAMPLE_DATA\Cities.jmp" );
//delete some columns from this table to make it fit your example
dt << delete columns( "PM10", "X", "Y" );
//change name of data table to ensure this modified version doesn't get saved
//over the sample data
dt << set name( "CitiesModified" );
//again I need a list of columns to use in the Stack()
mycols = {};
For( i = 9, i <= N Cols( dt ), i++,
Insert Into( mycols, Column( dt, i ) )
);
//stack those columns creating a new data table
stacked_dt = dt << Stack(
columns( Eval( mycols ) ),
Source Label Column( "Gas" ),
Stacked Data Column( "PPM" )
);
missing_rows = stacked_dt << get rows where( Is Missing( :PPM ) );
stacked_dt << delete rows( missing_rows );
回复:选择包含空数据的单元格选择包含空单元格的行的另一种方法:
dt << select where(!Contains(Loc Nonmissing(dt << get as matrix), Row()));
回复:选择包含空数据的单元格非常光滑。不知道你可以插入表达式(e)。我想插入需要一个清单。
回复:选择包含空数据的单元格相同的答案PM罗兹使用表达式操作:
dt = Current Data Table();
e = Expr( Or() ); // the OR of the ismissing(columns) will be built here
nc = dt << get column names( Numeric );
For( i = 1, i <= N Items( nc ), i++,
Insert Into( e, Eval Expr( Is Missing( Expr( nc ) ) ) )
);
dt << selectwhere( e );
表达式“e”看起来像
nameexpr(e)
/*:
Is Missing( :m1 ) | Is Missing( :m2 ) | Is Missing( :m3 ) | Is Missing( :m4 ) | Is Missing( :m5 ) | Is Missing( :m6 )
Head Arg 递归公式
内省

回复:选择包含空数据的单元格您可以使用 STACK 命令来堆叠数据,包括 M1-Mn 的值。然后选择空行并将其删除。
或者试试这个代码:
dt = Current Data Table();
col_list = dt << get column names( Numeric, string );
where_clause = "";
For( i = 1, i <= N Items( nc ), i++,
one_col = col_list[i];
if (i == 1,
// then
where_clause =evalinsert("\[dt << select where(is missing(as column(dt, "^one_col^"))]\");
// else
,
where_clause = evalinsert("\[^where_clause^ | is missing(as column(dt, "^one_col^"))]\");
);
);
where_clause = where_clause || ")";
eval(parse(where_clause));