回复:我正在嘗試將帶有字符(“<”)的列重置為數字,並在另一列中保留“<”附表,以防萬一。
回复:我正在嘗試將帶有字符(“<”)的列重置為數字,並在另一列中保留“<”這可能會給你一些關於你可以做什麼的想法
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!抱歉我回慢了。我剛剛回來查看了線程。
我很高興看到另一種技術。