為列分配最小值嗨伙計,
我有 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,.));
);回复:為列分配最小值附加文件