为列分配最小值嗨伙计,
我有 2 个文件。
第一个文件:

第二个文件:

我正在尝试编写一个脚本,该脚本将从第一个文件中搜索最低年龄并在第二个文件中分配最低年龄
例如
第一行有三个名字山姆、约翰、史密斯所以最小年龄列中的值应该是Min{Sam, John, Smith} Min{21, 27, 32} = 21
我的最终输出看起来像这样:

有什么建议吗?
谢谢
脚本回复:为列分配最小值Column() 函数不是
d2:Column(2)[I]
如前所述
Column( dt, 2 )[I]
如果索引是变量,则完成的脚本将是
Names Default To Here( 1 );
dt1 = Data Table( "1st" );
dt2 = Data Table( "2nd file" );
indexd2minage = 2;
indexd2name = 1;
indexd1name = 1;
indexd1age = 2;
Current Data Table( dt1 );
For( i = 1, i <= N Rows( dt2 ), i++,
Column( dt2, indexd2minage )[i] =
Col Min(
If(
Contains(
Column( dt2, indexd2Name )[i],
as Column( dt1, indexd1Name )
),
Column( dt1, indexd1age ),
.
)
)
);回复:为列分配最小值你好@txnelson ,
我试图用列索引替换列名,但它没有运行
有什么建议么?
Names default to here(1);
dt1=data table("1st");
dt2=data table("2nd file");
current data table(dt1);
For(i=1,i<=nrows(dt2), i++,
dt2:Column(2)[i] =col min(If(contains(dt2:Column(1)[i],dt1:Column(1)),dt1:Column(2),.));
);
回复:为列分配最小值我的意思是在这个脚本中用列索引替换列名
Names Default To Here( 1 );
dt1 = Data Table( "1st" );
dt2 = Data Table( "2nd file" );
Current Data Table( dt1 );
For( i = 1, i <= N Rows( dt2 ), i++,
dt2:Minimum Age[i] = Col Min( If( Contains( dt2:Name[i], dt1:Name ), dt1:age, . ) )
);
回复:为列分配最小值这是我举的例子之一
Column( "Age" ) << Get Property( "Units" );
如果您查看 JSL Syntax Reference 中有关 Column() 函数的文档,它会显示
Column(<dt>, "name", "formatted")
Column(<dt>, n)
Description
Gets a reference to the data table column.
Arguments
dt Optional reference to a data table. If this is not supplied, the current data table is used.
name Quoted string that is the name of the column.
formatted Quoted string that returns the formatted string of the cell value.
n Column number.
如果您阅读语法指南中的示例,它会显示:
The Column function can also identify a column. For Big Class.jmp, the following expressions
all refer to age, the second column in the table:
Column( "age" );
Column( 2 );
Column( dt, 2 );
Column( dt, "age" );
回复:为列分配最小值你好@txnelson ,
如何在上面的脚本中定义列索引而不是列名?
谢谢
回复:为列分配最小值获取属性的语法是
obj << Get Property( the property you want to retrive );
因此,您会要求 Age 列的列属性之一为:
:Age << Get Property( "Spec Limits" );
// or
Column( "Age" ) << Get Property( "Units" );
JMP 允许创建自己的列属性,因此您可以执行类似
dt1:Sam << Set Property("Age", 3);
dt1:Andy << Set Property("Age", 4);<BR />theAge = dt1:Andy << Get Property( "Age" );
回复:为列分配最小值你好@txnelson ,
谢谢你快速的回复。
我没有澄清我的问题。
1.在数据表 1st_file 中,你有 9 列是的
2. 在数据表 1st_file 中,每一列都有 1 行数据。
如果您右键单击列标题,然后选择“列属性”,您将看到广泛的清单引用您选择的特定列的项目。
我可以将这些广泛的列表值导入 2nd_file 的列吗?
我们可以使用语法“获取属性() “
例如.
dt1 << 获取属性("年龄");
然后使用 for 循环将其分配到第二个文件中?
再次感谢
回复:为列分配最小值首先,我需要澄清一些术语。
- 在数据表 1st_file 中,你有 9 列
- 在数据表 1st_file 中,每一列都有 1 行数据。您没有 JMP 所指的列属性。如果您右键单击列标题并选择“列属性”,您将看到一个广泛的项目列表,这些项目涉及您选择的特定列。
我说上面这些,只是因为当你用到Column Property这个关键词的时候,我马上就想到了JMP Column Properties。这设置了一堆错误的假设,给我带来了一堆困惑。
除此之外,这里有很多方法可以解决你的问题
Names Default To Here( 1 );
dt1 = Data Table( "1st_file" );
dt2 = Data Table( "2nd file" );
dt2 << New Column( "Minimum Age" );
// Transpose the data into a standard data table format
dt3 = dt1 << Transpose(
invisible,
columns( :Sam, :Andy, :John, :Ed, :Jonny, :Smith, :Scott, :George, :Mathew ),
Output Table( "Transpose of 1st_file" )
);
Current Data Table( dt3 );
For( i = 1, i <= N Rows( dt2 ), i++,
dt2:Minimum Age[i] = Col Min( If( Contains( dt2:Name[i], dt3:Label ), dt3:Name( "Row 1" ), . ) );
Show( dt2:minimum Age[i] );
);
Close( dt3, nosave );
处理数据需要多花点时间,但不需要创建辅助表。
Names Default To Here( 1 );
dt1 = Data Table( "1st_file" );
dt2 = Data Table( "2nd file" );
dt2 << New Column( "Minimum Age" );
For( i = 1, i <= N Rows( dt2 ), i++,
ages = {};
For( k = 1, k <= N Cols( dt1 ), k++,
If( Contains( dt2:Name[i], (Column( dt1, k ) << get name) ) > 0,
Insert Into( ages, Column( dt1, k )[1] )
);
);
dt2:Minimum Age[i] = Min( ages );
);回复:为列分配最小值你好@txnelson ,
如果 Age 值存储在列属性中怎么办? 如何将第一个文件的列属性(年龄)导入第二个文件的列(最小年龄)

回复:为列分配最小值是什么让你无法从“向数据表添加新列“并将其添加到您的脚本中?
您知道吗,您可以访问脚本指南并获取有关如何做事的示例?如果没有,我强烈建议您熟悉它。
这是我给你的示例脚本,带有添加新列的新命令
Names default to here(1);
dt1=data table("1st");
dt2=data table("2nd file");
dt2 << New Column( "Minimum Age" );
current data table(dt1);
For(i=1,i<=nrows(dt2), i++,
dt2:Minimum Age[i] =col min(If(contains(dt2:Name[i],dt1:Name),dt1:age,.));
);回复:为列分配最小值你好@txnelson ,
谢谢你的帮助。
第二个文件没有最低年龄列。 如何创建名称为“最小年龄”的第二列,然后分配最低值?
回复:为列分配最小值这是一个简短的脚本,可以做你想做的事......关键是大多数人没有意识到传递给计算函数的东西可以是有条件的。请参阅下面的脚本
Names default to here(1);
dt1=data table("1st");
dt2=data table("2nd file");
current data table(dt1);
For(i=1,i<=nrows(dt2), i++,
dt2:Minimum Age[i] =col min(If(contains(dt2:Name[i],dt1:Name),dt1:age,.));
);回复:为列分配最小值附加文件