如何将一个表的列代码链接到另一个表数据集大家好,我有 2 个数据表。我的数据集表“Dataset.jmp”的列数据为代码“ENICITY”和“ETHCAT”,我需要将其与数据集“Dictionary.jmp”链接,以便将代码更改为标签(在 Dictionary 文件的 Labels 列中)。我的实际数据集有 50 个类别,因此我无法使用所有类别的“值标签”函数。有什么想法可以将一个表的行链接到另一个表的具有精确值的列?我想要的列是 Dataset.jmp 文件上的结果列
我在此处附加了文件。
太感谢了!
最好的,
基础数据分析与建模回复:如何将一个表的列代码链接到另一个表数据集通过匹配,您只需列出发生变化的列,其余列保持“col” - 最后一个条目。
如果您不想建立映射,只需对列和字典使用匹配的名称。
或者,使用一致的映射(例如:列名的第一个字符。或者前两个字符)和相应的方程。
回复:如何将一个表的列代码链接到另一个表数据集谢谢 Hogi,但是,您能提供不需要重新输入我们拥有的所有列(超过 50 列)的脚本吗?
谢谢 !
回复:如何将一个表的列代码链接到另一个表数据集另一种选择是-不进行任何子集/For Each:
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 中有一个功能非常接近您想要的功能:从表中应用映射


目前它没有指定正确子集的设置。因此,如果您经常应用此类映射(其他用户也这样做),您可能希望在愿望清单中发布愿望,以通过此类设置增强功能...
回复:如何将一个表的列代码链接到另一个表数据集谢谢吉姆和贾莫,
我从讨论社区学到了很多东西。谢谢你的帮助,我试图找到与我想做的事情相关的主题,并从这个社区得到了答案。JIM 和你给我的脚本都有效。但是,我的实际数据比示例更复杂。例如,如果我在数据集中使用具有多列的同一套字典,例如我附加了新的数据集 1 和字典 1。如果 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();
首先,您一定要完全理解 Jim 提供的选项。然后,您也许可以开始考虑使用类似这样的方法(如果您对编程有一定了解),因为这基本上跳过了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 执行这些操作,并将它们放入脚本中。然后可以将步骤的循环添加到脚本中。
回复:如何将一个表的列代码链接到另一个表数据集您可以通过列属性使用虚拟连接。
回复:如何将一个表的列代码链接到另一个表数据集嗨,Jim,谢谢你的想法。但是,我的数据超过 50 列和 1000 行,你对更大的数据集有什么想法吗?
最好的,
回复:如何将一个表的列代码链接到另一个表数据集查看
表=>连接
根据 Column 列将数据表 Dictionary 子集化为 ETHCAT 表和 ETHNICITY 表。将 Value 列更改为数字列。对于 ETHNICITY 数据表,需要将 Null 或 Missing 扩展为 2 行,其中 Value 的值为 .,另一行的值为 0
将每个子集表连接到称为数据集的数据表,将 ETHNICITY 与一个表的值连接,将 ETHCAT 与第二个表的值连接。