JSL 不會設置列格式大家好,
我正在嘗試將列名、數據類型、建模類型和格式從一個表複製到一個新表中,但是當我嘗試設置列格式時,它永遠不會採用,只會恢復為“最佳”。 一段時間以來,我一直在努力解決這個問題,並且完全不知道為什麼它不起作用。 下面是我的代碼和顯示列格式的結果輸出是有效的,但只是不堅持。 日誌中沒有報告任何錯誤。 誰能看到我做錯了什麼?
summaryTable = New Table( "Results Summary" );
colNames = data << Get Column Names( string );
For( i = 1, i <= N Items( colNames ), i++,
colType = Column( data, colNames[i] ) << Get Data Type;
colModel = Column( data, colNames[i] ) << Get Modeling Type;
colFormat = Column( data, colNames[i] ) << Get Format;
Show( colNames[i] );
Show( colType );
Show( colModel );
<STRONG> Show( colFormat );</STRONG>
newCol = summaryTable << New Column( colNames[i] );
newCol << Data Type( colType ) << Modeling Type( colModel );
If( colType != "Character",
newCol << Format( colFormat );
<STRONG> Show( newCol << Get Format );</STRONG>
);
);
colNames[i] = "Label";
colType = "Character";
colModel = "Nominal";
colFormat = Format("Best");
colNames[i] = "Start_Time";
colType = "Numeric";
colModel = "Continuous";
<STRONG>colFormat = Format("m/d/y h:m:s", 23, 0);
newCol << Get Format = Format("Best", 10);</STRONG>
colNames[i] = "End_Time";
colType = "Numeric";
colModel = "Continuous";
<STRONG>colFormat = Format("m/d/y h:m:s", 23, 0);
newCol << Get Format = Format("Best", 10);</STRONG>獎金後續問題:我似乎只能使用上面的代碼設置列數據和建模類型,我在列初始化後設置類型。 當我嘗試執行下面的行時,列根本沒有初始化,為什麼不呢?
newCol = summaryTable << New Column( colNames[i], colType, colModel );
腳本回复:JSL 不會設置列格式謝謝大家。 我考慮過複製表格並刪除行。 數據表由大約 2 打列組成,可能包含數百行。 我認為迭代創建 2 打列可能比潛在地刪除數百行更有效。@pmroz的子集方法雖然很聰明,但我可能會使用它。
回复:JSL 不會設置列格式假設桌子不是很大,並且基於 Mark 的想法,您也可以這樣做:
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Eval(dt << getScript);
dt2 << selectAllRows;
dt2 << deleteRows;回复:JSL 不會設置列格式使用子集的更簡單的邏輯:
data = New Table( "Test Data", Add Rows( 3 ),
New Column( "Column 1", Numeric, "Continuous", Format( "Fixed Dec", 8, 0 ),
Set Values( [1, 2, 3] )
),
New Column( "Column 2", Character, "Nominal", Set Values( {"c", "b", "a"} ) ),
New Column( "Column 3", Numeric, "Continuous", Format( "m/d/y", 10 ),
Input Format( "m/d/y" ),
Set Values( [3630873600, 3633552000, 3635971200] )
)
);
summaryTable = data << Subset( Rows( [1] ));
summarytable << delete rows([1]) << set name( "Results Summary");
回复:JSL 不會設置列格式感謝您的答复。 我想我沒有提到“數據”是由多個 SQL 查詢和計算創建的已經存在的表。 我想用與“數據”相同的列組裝一個匯總表,而不實際對其進行子集化。 我稍後以分段方式填充行。
@pmroz您的方法有效,謝謝! 我仍然不明白為什麼指針不起作用,但我已經不在乎了。
回复:JSL 不會設置列格式此代碼將執行此操作:
data = New Table( "Test Data", Add Rows( 3 ),
New Column( "Column 1", Numeric, "Continuous", Format( "Fixed Dec", 8, 0 ),
Set Values( [1, 2, 3] )
),
New Column( "Column 2", Character, "Nominal", Set Values( {"c", "b", "a"} ) ),
New Column( "Column 3", Numeric, "Continuous", Format( "m/d/y", 10 ),
Input Format( "m/d/y" ),
Set Values( [3630873600, 3633552000, 3635971200] )
)
);
summaryTable = New Table( "Results Summary" );
colNames = data << Get Column Names( string );
For( i = 1, i <= N Items( colNames ), i++,
colType = Column( data, colNames[i] ) << Get Data Type;
colModel = Column( data, colNames[i] ) << Get Modeling Type;
colFormat = char(Column( data, colNames[i] ) << Get Format);
Show( colNames[i] );
Show( colType );
Show( colModel );
Show( colFormat );
newCol = summaryTable << New Column( colNames[i] );
newCol << Data Type( colType ) << Modeling Type( colModel );
if (coltype != "Character",
new_expr = "newcol << " || colformat;
eval(parse(new_expr));
);
);回复:JSL 不會設置列格式保存原始數據表的副本並打開副本繼續操作會更容易嗎?
回复:JSL 不會設置列格式你好,
首先,我認為“數據”沒有定義。
Clear Globals();
summaryTable = New Table( "Results Summary" );
colNames = data << Get Column Names( string );
結果是
Data Table( "Results Summary" )
//:*/
colNames = data << Get Column Names( string );
/*:
Send Expects Scriptable Object in access or evaluation of 'Send' , data << /*###*/Get Column Names( string ) /*###*/
In the following script, error marked by /*###*/
colNames = data << /*###*/Get Column Names( string ) /*###*/
{}