迭代開啟的資料表的列表並連接成一個表我正在嘗試將一堆日誌文件連接到一個文件中,並且我正在使用版本 13 ...JMP 14 更容易... 由於其他人將在 jmp 13 上使用一段時間,因此我需要製作一個通用腳本。
我此時的腳本可以產生一堆開啟的資料表。 效果很好。我可以迭代並捕獲 openDT 列表..
但是當我嘗試連接時我沒有成功。 我什至不需要打開表,只需連接到一個文件即可。
有人可以幫助我理解這個問題嗎?
_____________________________________________________
我在其中一個打開的日誌上運行了連接函數並產生了以下內容:
Data Table( "test_data_1.log" ) << Concatenate(
Data Table( "test_data_2.log" ),
Data Table( "test_data_3.log" ),
Output Table( "RESULTS" ),
Create source column
);
___________________________________________________
names = {"/C:/1test/test_data_1.log", "/C:/1test/test_data_2.log", "/C:/1test/test_data_3.log"};
openDTs = {DataTable("test_data_3.log"), DataTable("test_data_2.log"), DataTable("test_data_1.log")};
名稱未解析:導致訪問或評估“結果”,結果/*###*/
在以下腳本中,錯誤標記為 /*###*/
dirpath = Munger( Pick Directory( "JMP 13.xx locate the LOG FILES: " ), 1, "/", "" );
Set Current Directory( dirpath );
names = Files In Directory( dirpath, recursive( 1 ) );
For( i = 1, i <= N Items( names ), i++,
dt1 = Open(
names[i] = Convert File Path( dirpath ) || names[i],
columns(
Column( "STARTDATETIME", Numeric, "Continuous", Format( "y/m/d h:m:s", 26, 3 ), Input Format( "y/m/d h:m:s", 3 ) ),
Column( "FIVER", Numeric, "Continuous", Format( "Best", 12 ) ),
Column( "CLASS", Character, "Nominal" ),
Column( "BLANK", Character( 1 ), "Nominal" ),
Column( "TYPE", Character, "Nominal" ),
Column( "CSTARGET", Character, "Nominal" ),
Column( "CSACTION", Character, "Nominal" ),
Column( "NUMCODE", Numeric, "Continuous", Format( "Best", 12 ) ),
Column( "DEVICE", Character, "Nominal" ),
Column( "DATA", Character, "Nominal" ),
Column( "ENDDATE", Numeric, "Continuous", Format( "y/m/d h:m:s", 29, 6 ), Input Format( "y/m/d h:m:s", 6 ) ),
Column( "JUNK1", Numeric, "Continuous", Format( "y/m/d h:m:s", 29, 6 ), Input Format( "y/m/d h:m:s", 6 ) ),
Column( "JUNK2", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Other( "0x7c" ), CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
Current Data Table( dt1 );
dt1 << delete columns( "CLASS", "FIVER", "BLANK", "JUNK1", "JUNK2" );
dt1 << Select Where(
Contains( As Column( dt1, "TYPE" ), "Execute" ) | Contains( As Column( dt1, "TYPE" ), "++" ) | Contains(
As Column( dt1, "TYPE" ),
"SetState"
) | Contains( As Column( dt1, "TYPE" ), "SAM" ) | Contains( As Column( dt1, "TYPE" ), "DAC" )
);
dt1 << Delete Rows;
);
Show( names );
openDTs = {};
For( i = 1, i <= N Table(), i++,
Insert Into( openDTs, Data Table( i ) )
);
Show( openDTs );
dt = New Table( "Results" );
For( k = 1, k <= N Items( names ), k++,
Current Data Table( Results/*###*/ );
dt << concatenate( Data Table( names[k] ), Output Table( "Results" ), Create Source column );
);回覆:迭代開啟的資料表的列表並連接成一個表吉姆 - 謝謝...做了一次大修....在沒有將資料解析為列的情況下,我打開文件,然後添加來源列。 然後串聯起來。 然後取出連接的檔案並將其解析出來。 它的進展更快、更合乎邏輯。新增了以下內容:
// create the variables to set the column name and
// define the column value
cName = "SOURCE";
fName = dt1 << get name;
dt1 << New Column( cName, Character, Nominal, Set each value( fName ) );
Then iterate the open tables:
// define a list of open data tables.
openDTs = List();
For( i = 1, i <= N Table(), i++,
Insert Into( openDTs, Data Table( i ) )
);
// Loop through the data tables again and concatenate
For( k = 2, k <= N Items( openDTs ), k++,
Current Data Table();
dtUpdated = Current Data Table() << Concatenate( openDTs[k] );
Close( openDTs[k], nosave );
);
現在運作良好。
回覆:迭代開啟的資料表的列表並連接成一個表您的 Current Data Table() 函數需要更改為
Current Data Table( dt );
或者
Current Data Table( data table( "Results" ) );
但是,我通常在讀入每個文件時進行串聯。對我來說它看起來更乾淨
Names default to here(1);
dirpath = Munger( Pick Directory( "JMP 13.xx locate the LOG FILES: " ), 1, "/", "" );
Set Current Directory( dirpath );
names = Files In Directory( dirpath, recursive( 1 ) );
dt = New Table( "Results" );
For( i = 1, i <= N Items( names ), i++,
dt1 = Open(
names[i] = Convert File Path( dirpath ) || names[i],
columns(
Column( "STARTDATETIME", Numeric, "Continuous", Format( "y/m/d h:m:s", 26, 3 ), Input Format( "y/m/d h:m:s", 3 ) ),
Column( "FIVER", Numeric, "Continuous", Format( "Best", 12 ) ),
Column( "CLASS", Character, "Nominal" ),
Column( "BLANK", Character( 1 ), "Nominal" ),
Column( "TYPE", Character, "Nominal" ),
Column( "CSTARGET", Character, "Nominal" ),
Column( "CSACTION", Character, "Nominal" ),
Column( "NUMCODE", Numeric, "Continuous", Format( "Best", 12 ) ),
Column( "DEVICE", Character, "Nominal" ),
Column( "DATA", Character, "Nominal" ),
Column( "ENDDATE", Numeric, "Continuous", Format( "y/m/d h:m:s", 29, 6 ), Input Format( "y/m/d h:m:s", 6 ) ),
Column( "JUNK1", Numeric, "Continuous", Format( "y/m/d h:m:s", 29, 6 ), Input Format( "y/m/d h:m:s", 6 ) ),
Column( "JUNK2", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Other( "0x7c" ), CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
Current Data Table( dt1 );
dt1 << delete columns( "CLASS", "FIVER", "BLANK", "JUNK1", "JUNK2" );
dt1 << Select Where(
Contains( As Column( dt1, "TYPE" ), "Execute" ) | Contains( As Column( dt1, "TYPE" ), "++" ) | Contains(
As Column( dt1, "TYPE" ),
"SetState"
) | Contains( As Column( dt1, "TYPE" ), "SAM" ) | Contains( As Column( dt1, "TYPE" ), "DAC" )
);
dt1 << Delete Rows;
dt1 << rerun formulas; // make sure all dt1 operations are complete
// Concatenate to the Results data table
dt << concatenate( dt1, Append to first table( 1 ), Create Source Column );
// To keep the work environment clean, I normally delete the latest input data table
close( dt1, nosave );
);