如何將一個表的列代碼連結到另一個表資料集大家好,我有2張數據表。我的資料集表“Dataset.jmp”的列資料為代碼“ENICITY”和“ETHCAT”,我需要將其與資料集“Dictionary.jmp”鏈接,可以將程式碼變更為標籤(在字典檔案的“標籤”列中) 。我的實際資料集有 50 個類別,因此我無法使用所有類別的「值標籤」功能。有什麼想法可以將一個表的行連結到另一個表的具有精確值的列嗎?我想要的列是 Dataset.jmp 檔案上的結果列
我將文件附在此處。
太感謝了!
最好的,
基礎資料分析與建模回覆:如何將列代碼從一個表格連結到另一個表格資料集使用 match f,您只需列出發生變更的列,其餘列保留「col」 - 最後一個項目。
如果您不想建立映射,只需對列和字典使用匹配的名稱即可。
或者,使用一致的對應(例如:列名稱的第一個字元。或前 2 個字元)和對應的方程式。
回覆:如何將列代碼從一個表格連結到另一個表格資料集謝謝 Hogi,但是,您能否提供不需要重新輸入我們擁有的所有列(超過 50 列)的腳本?
謝謝 !
回覆:如何將列代碼從一個表格連結到另一個表格資料集作為另一種選擇 - 沒有任何子集/對於每個:
names default to here(1);
dict = Open( "$DOWNLOADS/Dictionary1.jmp" );
dt = Open( "$DOWNLOADS/Dataset1.jmp" );
// stack the data for easy application of the dictionary
dt2=dt << Stack(
columns(
:ETHNICITY, :ETHCAT, :SEX, :NAME, :"A09:05"n, :"A01:01"n, :DPA05, :DPB04
),
Source Label Column( "col" ),
Stacked Data Column( "values" )
);
// add a column with the corrected column-identifiers
dt 2 << New Column( "column",
Character,
Formula(
Match( :col,
"A01:01", "A",
"A09:05", "A",
"DPA05", "DP",
"DPB04", "DP",
:col
)
)
);
<BR />// add the labels from the disctionary
dt2 <<
Update(
With( dict ),
Match Columns( :column = :Column, :values = :Values ),
Add Columns from Update Table( :Labels )
);<BR />
// convert back to a wide table
dt2 <<
Split(
Split By( :col ),
Split( :Labels ),
Group( :ID ),
Remaining Columns( Drop All )
);
回覆:如何將列代碼從一個表格連結到另一個表格資料集對於這種情況,只需新增一個映射即可取得正確的子集,例如在 Jarmos 程式碼中:
colMapping = Associative array({{"SEX","SEX"},{"NAME","NAME"},{"A09:05","A"},{"A01:01","A"},{"DPA05","DP"},{"DPB04","DP"}});
colIndex= colMapping[col];
dt_dict_subset = dt_dict << Subset(Rows(dt_dict << get rows where(:Column == colIndex)), Selected Columns(0), Invisible);
替代想法:Recode 中有一個功能非常接近您想要的功能: Apply Mapping from Table


目前它沒有指定正確子集的設定。因此,如果您定期應用此類映射(其他用戶也這樣做),您可能希望在願望清單中發布願望,以透過此類設定增強功能...
回覆:如何將列代碼從一個表格連結到另一個表格資料集謝謝吉姆和賈莫,
我從討論社群學到了很多。感謝您的幫助,我嘗試找到與我想做的事情相關的主題,並從這個社區得到了答案。吉姆和你給我的腳本是可行的。然而,我的真實數據比範例更複雜。例如,如果我在資料集中使用具有多個列的相同字典,例如我附加了新的 dataset1 和dictionary1。如果 1 列與同一模式中的其他列共用,您能否修正此腳本?例如字典 A 和列 A01、A08、A9、...
我在這裡附上了新的數據集。
最好的,
回覆:如何將列代碼從一個表格連結到另一個表格資料集我肯定會從 Jim 提供的解決方案開始,因為它更多地利用了 JMP 提供的 JSL,但這是我在積累了大量JSL 和JMP 經驗後編寫的內容(我的部分工作是透過腳本實現JMP 自動化並添加額外功能)使用 JSL 到 JMP...)
看更多...
Names Default To Here(1);
dt_data = Open("$DOWNLOADS/Dataset.jmp");
dt_dict = Open("$DOWNLOADS/Dictionary.jmp");
Column(dt_dict, "Values") << Set Data Type("Numeric");
/*
// Not really sure if this "fix" should be done or not
missing_rows = Loc(dt_dict[0, "Values"], .);
If(N Rows(missing_rows) > 0,
dt_dict[missing_rows, "Values"] = 0;
);
*/
Summarize(dt_dict, cols = By(:Column));
For Each({col}, cols,
dt_dict_subset = dt_dict << Subset(Rows(dt_dict << get rows where(:Column == col)), Selected Columns(0), Invisible);
Column(dt_dict_subset, "Labels") << Set Name("Result " || col);
dt_data << Update(
With(dt_dict_subset),
Match Columns(Eval(col) = :Values),
Add Columns from Update Table(Eval("Result " || col))
);
Close(dt_dict_subset, no save);
);
Write();
首先,你絕對應該充分理解吉姆提供的選項。然後你也許可以開始考慮利用這樣的東西(如果你對程式設計有一定的了解),因為這基本上跳過了JMP 可以為你提供的大部分程式碼(大部分Open() 和<< Update 都是JMP提供的)。
如果您想了解 JSL以及如何自動化 JMP ,請不要在執行前面的步驟之前直接跳到我的解決方案
- 從純 JMP 提供的腳本開始
- 稍微改進它們(例如使用變數而不是“硬編碼”表名稱)
- 開始添加一些「編程」到混合中」。這就是我認為 Jim 的解決方案所屬的地方(例如 JMP 很可能無法為您提供並利用 Word() 函數的循環)
- 最終得到類似我的解決方案,該解決方案仍然部分利用JMP 提供的 JSL(打開表、更新表)
回覆:如何將列代碼從一個表格連結到另一個表格資料集這是您想要的一個好的開始。您應該能夠對此進行擴展,以滿足您的最終要求和差異。
如果您還沒有花時間閱讀 JMP 幫助下提供的腳本指南,我強烈建議您這樣做。另外,請確保您研究了下面的範例,以便您了解函數和語句的邏輯和細節。
names default to here(1);
// Open Data Table: Dataset.jmp
// → Data Table( "Dataset.jmp" )
dt = Open( "$Downloads/Dataset.jmp" );
// Open Data Table: Dictionary.jmp
// → Data Table( "Dictionary.jmp" )
dtDict = Open( "$Downloads/Dictionary.jmp" );
/*// Subset data table
// → Data Table( "Subset of Dictionary" )
Data Table( "Dictionary.jmp" ) << Clear Select << Select Rows( Index( 1, 10 ) ) <<
Subset( Selected Rows( 1 ), Selected columns only( 0 ) );
// Subset data table
// → Data Table( "Subset of Dictionary 2" )
Data Table( "Dictionary.jmp" ) << Clear Select << Select Rows( Index( 11, 14 ) ) <<
Subset( Selected Rows( 1 ), Selected columns only( 0 ) );*/
// Change column modeling type: Values
Data Table( "Dictionary" ):Values << Set Modeling Type( "Continuous" );
// Create a new dictionary data table for each level of the Column column
dtDictList = dtDict << Subset(
By( :Column ),
All rows,
Selected columns( 0 ),
Selected rows( 0 )
);
/*// Change column info: Values
Data Table( "Dictionary.jmp" ):Values << Data Type( Numeric ) <<
Set Field Width( 12 );*/
// Clear row selection
//Data Table( "Dataset.jmp" ) << Clear Select;
dt << Clear Column Selection();
// Change column modeling type: ETHNICITY
Data Table( "Dataset.jmp" ):ETHNICITY << Set Modeling Type( "Continuous" );
// Change column modeling type: ETHCAT
Data Table( "Dataset.jmp" ):ETHCAT << Set Modeling Type( "Continuous" );
/*// Change column modeling type: Values
Data Table( "Subset of Dictionary 2" ):Values << Set Modeling Type( "Continuous" );
// Change column modeling type: Values
Data Table( "Dictionary.jmp" ):Values << Set Modeling Type( "Continuous" );*/
For Each( {thedt, index}, dtDictList,
// Get the dataset column to join with
joinColumn = Word( 3, Char( thedt ), "=\!"" );
// Join data tables
// → Data Table( "untitled 1925" )
newDT = dt << Join(
With( thedt ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( Column( joinColumn ) = :Values ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 ),
Output Table( "Join of Dataset with Column=ETHCAT" )
);
NewDt:Labels << set name( joinColumn || " Labels" );
NewDt:Values << set name( joinColumn || " Values" );
If( index > 1,
Close( dt, nosave )
);
dt = newDT;
);回覆:如何將列代碼從一個表格連結到另一個表格資料集嗨吉姆,非常感謝你。你的建議很有效。但是,如果我有一個包含 150 行不同類別(從 5 到 30 個群組,例如 ETHCAT、ETHNICITY 等)的字典,並且資料集表上的一列需要與 300 列連接。老實說,手動執行此操作很困難,而且我有多個表連接在一起。您能否提供以下腳本:1.如何對字典檔案中的相同內容進行分類,以及如何將所有資料集列與字典僅 1 個檔案連接起來。這是我嘗試做的腳本。但是,我無法修改腳本。
// Open Data Table: Dataset.jmp
// → Data Table( "Dataset.jmp" )
Open( "$DOWNLOADS/Dataset.jmp" );
// Open Data Table: Dictionary.jmp
// → Data Table( "Dictionary.jmp" )
Open( "$DOWNLOADS/Dictionary.jmp" );
// Subset data table
// → Data Table( "Subset of Dictionary" )
Data Table( "Dictionary.jmp" ) << Clear Select << Select Rows( Index( 1, 10 ) ) <<
Subset( Selected Rows( 1 ), Selected columns only( 0 ) );
// Subset data table
// → Data Table( "Subset of Dictionary 2" )
Data Table( "Dictionary.jmp" ) << Clear Select << Select Rows( Index( 11, 14 ) ) <<
Subset( Selected Rows( 1 ), Selected columns only( 0 ) );
// Change column info: Values
Data Table( "Subset of Dictionary 2" ):Values << Data Type( Numeric ) <<
Set Field Width( 12 );
// Change column info: Values
Data Table( "Dictionary.jmp" ):Values << Data Type( Numeric ) <<
Set Field Width( 12 );
// Clear row selection
Data Table( "Dataset.jmp" ) << Clear Select;
// Change column modeling type: ETHNICITY
Data Table( "Dataset.jmp" ):ETHNICITY << Set Modeling Type( "Continuous" );
// Change column modeling type: ETHCAT
Data Table( "Dataset.jmp" ):ETHCAT << Set Modeling Type( "Continuous" );
// Change column modeling type: Values
Data Table( "Subset of Dictionary 2" ):Values << Set Modeling Type( "Continuous" );
// Change column modeling type: Values
Data Table( "Dictionary.jmp" ):Values << Set Modeling Type( "Continuous" );
// Join data tables
// → Data Table( "untitled 1925" )
Data Table( "Dataset.jmp" ) << Join(
With( Data Table( "Subset of Dictionary 2" ) ),
By Matching Columns( :ETHCAT = :Values ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 )
);
太感謝了,
最好的,
回覆:如何將列代碼從一個表格連結到另一個表格資料集為什麼行數和列數會產生問題。如果不同尋找(ETHCAT、ETHNICITY 等)的數量較多,則只需將子集化並放入循環中即可。然而,一開始是對 1 或 2 個群組進行互動操作,然後採用 JMP 產生的 JSL 來執行這些操作,並將它們放入腳本中。然後可以將步驟的循環新增到腳本中。
回覆:如何將列代碼從一個表格連結到另一個表格資料集您可以透過列屬性使用虛擬聯結。
回覆:如何將列代碼從一個表格連結到另一個表格資料集嗨吉姆,謝謝你的想法。但是,我有超過 50 列和 1000 行,您對更大的資料集有什麼想法嗎?
最好的,
回覆:如何將列代碼從一個表格連結到另一個表格資料集調查一下
表=>連接
依 Column 欄位將資料表字典子集為 ETHCAT 的表格和 ETHNICITY 的表格。將值列變更為數字列。對於 ETHNICITY 資料表,Null 或 Missing 需要擴充為 2 行,其中 Value 的值為 。 1 的值為 0
將每個子集表連接到名為 dataset 的資料表,將第一個表的 ETHNICITY 與 Value 連接,將第二個表的 ETHCAT 與 Value 連接。