查找和替换脚本我使用一个GCMS程序,当峰面积计数达到饱和时,它会添加“饱和(####)”。将这些结果从excel导出到JMP数据表后,我想运行一个脚本来查找这些出现并删除“ saturated()”,但将数字保留为连续的数字12,0格式。
脚本编写回复:查找和替换脚本以交互方式,使用“查找”功能对“(”和“)”进行全局替换非常容易。然后,使用“标准化属性”,可以选择所有有问题的列,并将它们更改为数字,连续,格式(固定的12月12日,0)
查找位于
编辑=>搜索=>查找
如果有数据表,则在左侧“列”面板中的红色三角形下可以使用“标准化属性”。
这是一个可以解决问题的小脚本,但是对于大数据表,它可能很慢
Names Default To Here( 1 );
dt = Current Data Table();
// Get all character columns
colList = dt << get column names( character, string );
// Loop across all character columns and find those who have the pattern (###)
// and if found, then convert all columns
For( I = 3, i <= N Items( colList ), i++,
If( Left( char(Column( dt, colList[i] )[1]), 1 ) == "(" & Right( char(Column( dt, colList[i] )[1]), 1 ) == ")",
For( k = 1, k <= N Rows( dt ), k++,
If( Left( (Column( dt, colLIst[i] )[k]), 1 ) == "(",
Column( dt, colList[i] )[k] = Substr( Column( dt, colList[i] )[k] ,
2)
);
If( Right( (Column( dt, colList[i] )[k]), 1 ) == ")",
Column( dt, colList[i] )[k] = Word( 1, Column( dt, colList[i] )[k], ")" )
);
);
// Convert to numeric, etc.
Column( dt, colList[i] ) << data type( numeric ) << modeling type( continuous ) <<
Format( "Fixed Dec", 12, 0 );
)
);回复:查找和替换脚本谢谢您的脚本,但看来我不够具体。编写脚本对我来说是很新的,我认为数字的长度没有关系。我猜这是错误的。我使用了该脚本,但无法将“ saturated(635403558)”转换为635403558。我感谢您的帮助。
回复:查找和替换脚本脚本期望“(”是第一个字符,而“)”是最后一个字符。空白字符是否可能在开头或结尾?
试试这个版本的脚本,看看是否有帮助
Names Default To Here( 1 );
dt = Current Data Table();
// Get all character columns
colList = dt << get column names( character, string );
// Loop across all character columns and find those who have the pattern (###)
// and if found, then convert all columns
For( I = 1, i <= N Items( colList ), i++,
If( Left( Trim( Char( Column( dt, colList[i] )[1] ) ), 1 ) == "(" & Right( Trim( Char( Column( dt, colList[i] )[1] ) ), 1 ) == ")",
For( k = 1, k <= N Rows( dt ), k++,
If( Left( (Trim( Column( dt, colLIst[i] ) )[k]), 1 ) == "(",
Column( dt, colList[i] )[k] = Substr( Trim( Column( dt, colList[i] )[k] ), 2 )
);
If( Right( Trim( Column( dt, colList[i] )[k] ), 1 ) == ")",
Column( dt, colList[i] )[k] = Word( 1, Column( dt, colList[i] )[k], ")" )
);
);
// Convert to numeric, etc.
Column( dt, colList[i] ) << data type( numeric ) << modeling type( continuous ) << Format( "Fixed Dec", 12, 0 );
)
);回复:查找和替换脚本如果我理解正确,这可能是一个使用机会JMP的模式匹配(谢谢@Craige_Hales
:(:(
NamesDefaultToHere(1);
// Define a function
removeSaturated =
Function({inStr}, {Default Local},
// A pattern that will match a span of digits, with or without a leading '-'
digits = (""|"-") + patSpan("0123456789");
// Put the match into 'found' (might be identical to 'inStr')
patMatch(inStr, digits >? found);
// Return 'found' as a number
Num(found);
);
// Try it out
Print(removeSaturated("saturated( 635403558 )"));
Print(removeSaturated("saturated(635403558)"));
Print(removeSaturated("635403558"));
Print(removeSaturated("635403"));
Print(removeSaturated("-635403"));
Print(removeSaturated("saturated( -635403 )"));
回复:查找和替换脚本可悲的是,当我运行脚本时没有任何反应。如果有帮助,我还提供了我的数据以及列属性的屏幕截图。再次感谢!

回复:查找和替换脚本在您的“面积”列上尝试一下
Names Default To Here( 1 );
dt = Current Data Table();
// Loop across all character columns and find those who have the pattern (###)
// and if found, then convert all columns
For( k = 1, k <= N Rows( dt ), k++,
If( Contains( :Area[k], "(" ),
:Area[k] = Word( 2, :Area[k], "()" )
)
);
:Area << data type( numeric ) << modeling type( continuous ) << Format( "Fixed Dec", 12, 0 );