回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”附表,以防万一。
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”这可能会给你一些关于你可以做什么的想法
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(2),
Compress File When Saved(1),
New Column("Column 1", Character, "Nominal", Set Values({"<1", "<3"})),
New Column("Column 2", Character, "Nominal", Set Values({"<2", "<4"}))
);
col_names = dt << Get Column Names("String");
For Each({col_name}, col_names,
dt << New Column(col_name ||"_Q", Numeric, Continuous, << Set Each Value(
Num(Substitute(AsColumn(dt, col_name), "<", ""));
));
);
搜索 Substitute() 的脚本索引和脚本指南,了解有关如何使用它的更多信息
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”只需用对您的表格的引用替换该部分即可。 如果您知道应该使用哪一个列,您可能还想清理列选择(而不是仅使用 << get column name("String") 来获取所有列)。
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”不幸的是,我没有遵循该代码如何应用于我原来的问题。我可能在我原来的帖子中不清楚或者遗漏了一些东西(我是 jsl 新手)。无论如何,我会继续尝试,并且可能需要重新构建我的问题。(顺便说一句,我有大量的列在使用,除了日期时间列之外的所有列都需要这种处理 - 太多而无法手动定义。)再次感谢。
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”下面是一个脚本,用于检查 < 和任何 Post Script 值(例如“J”或“UJ”等),并将这些值移动到新的限定符列。然后,它将列从字符列转换为数字列

Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column names( string, character );
For Each( {col, i}, colNames,
GTFound = "NO";
postScriptFound = "NO";
// Find rows that have < in them
theRows = dt << get rows where( Contains( As Column( dt, col ), "<" ) );
// If < is found then
// 1. Create a new column to hold the < in
// 2. Loop through the rows with < and
// 1. Add < to the appropriate row in the new Qualifier column
// 2. Delete the < from the current column
If( N Rows( theRows ) > 0,
GTFound = "YES";
dt << add Multiple Columns( col, 1, Character );
Column( dt, N Cols( dt ) ) << set name( col || "_QUALIFIER" );
dt << move selected column( after( As Column( col ) ) );
For Each( {fixRow, k}, theRows,
As Column( dt, col || "_QUALIFIER" )[fixRow] = "<";
As Column( dt, col )[fixRow] = Substr( Column( col )[fixRow], 2 );
);
);
// Find if there are any post script values on any of the rows
theRows = dt << get rows where( Word( 2, As Column( dt, col ), " " ) != "" );
// If found, then if a new column has not already been add, add the new Qualifer column
If( N Rows( theRows ) > 0,
postScriptFound = "YES";
If( GTFound == "NO",
dt << add Multiple Columns( col, 1, Character );
Column( dt, N Cols( dt ) ) << set name( col || "_QUALIFIER" );
dt << move selected column( after( As Column( col ) ) );
);
// Loop through the rows with post scripts and
// 1. Add the post scripts to the Qualifer column
// 2. Delete the post scripts from the current column
For Each( {fixRow, k}, theRows,
As Column( dt, col || "_QUALIFIER" )[fixRow] = Trim(
As Column( dt, col || "_QUALIFIER" )[fixRow] || " " || Word( 2, As Column( dt, col )[fixRow], " " )
);
As Column( dt, col )[fixRow] = Word( 1, As Column( dt, col )[fixRow], " " );
);
);
// If eiter < or Post Scripts were found, convert the column to numeric, continuous
If( GTFound == "YES" | postScriptFound == "YES",
Column( dt, col ) << data type( numeric ) << modeling type( continuous )
);
);
我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”您好 - 我有一个表,其中的列由作为文本字符串输入的实验室结果(数值)组成。它们是文本字符串,因为有些在数值前面有一个“<”。我需要能够对值执行数值计算,因此我尝试删除“<”符号并将其放置在名为“ORIGCOLNAME_QUALIFIER”的新列中(其中 ORIGCOLNAME 是“<”所在的列的名称) " 符号已被删除)。
不幸的是,下面的代码不起作用。
Names Default To Here( 1 );
dt = Current Data Table();
compList = {};
For( i = 1, i <= N Cols( dt ), i++,
colName = Column( dt, i ) << get name;
);
// Create the columns
For Each( {comp, i}, compList,
Eval(
Parse(
"dt << New Column( \!"" || compList[i] || "_QUALIFIER" ||
"\!",
character, nominal,
formula(
x=.;
if (comp << contains ("<"), x = <);
我收到以下消息:

任何意见将不胜感激。
基础数据分析和建模内容组织数据混合和清理回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”谢谢 jthi - 代码的第一部分创建一个新的 2 行表,其中包含预先命名的列。
Names Default To Here( 1 );
dt = New Table( "Untitled",
Add Rows( 2 ),
Compress File When Saved( 1 ),
New Column( "Column 1", Character, "Nominal", Set Values( {"<1", "<3"} ) ),
New Column( "Column 2", Character, "Nominal", Set Values( {"<2", "<4"} ) )
);
但是,我试图保持列名称完整,同时添加一个新列,其名称与每个现有列相对应,但末尾带有“_qualifier”。(例如:假设我现有的列是氯化物(字符)、硫酸盐(硫酸盐)……,新列将是氯化物(数字)、硫酸盐(数字)、氯化物限定符(字符)、硫酸盐限定符(字符)等。
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”效果非常好。注释行是最有帮助的,因为它们将帮助我理解该过程中的每一步。当我学习如何将这些 jsl 基础知识实际应用到我的数据集时,这丰富了我在帮助文档中可以找到的内容。非常感谢。
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”我可能不理解您的需求,并且可能有更有效的方法来执行此操作,特别是如果您的数据有很多行,但如果此表看起来像您想要的结果,那么这里有一个强力方法。

Names Default To Here(1);
id_colnames = {"well", "Sample Date"};
dt = Current Data Table();
nr =nrow(dt);
col_names = dt << Get Column Names("String");
For Each({col_name}, col_names,
If( !Contains(id_colnames, col_name),
dt << New Column(col_name||"_Q", Character, << Set Each Value(
If(Contains(AsColumn(dt,col_name), "<"), "<",""))
);
curr_col = column(dt,col_name);
For(i=1, i<=nr, i++,
curr_col[i]= Substitute( word(1, curr_col[i]) ,"<","");
);
curr_col << Set Data Type(Numeric) << Set Modeling Type ("Continuous");
); // end If()
); //end For Each()
回复:我正在尝试将带有字符(“<”)的列重置为数字,并在另一列中保留“<”感谢 GZMorngan0!抱歉我回复慢了。我刚刚回来查看了线程。
我很高兴看到另一种技术。