取得具有特定截止值的列名稱你好,
我嘗試從這些資料範例中計算並獲取特定的列名稱(我的真實資料包含 180 列和 20000 行)
我想選擇截止值 > 1000 的列
| 不。 | A*1:01 | A*2:01 | 下*9:02 | C*10:01 | 博士*56:01 | DP*07_G | 獲取姓名 |
| 1 | 10.67 | 0 | 9520.23 | 15000.1 | 90.56 | 40.89 | 乙*9:02,乙*10:01 |
| 2 | 0 | 0 | 0 | 0 | 0 | 9.56 | |
| 3 | 9040.3 | 345.3 | 345.9 | 999.9 | 第345章 | 10.5 | A*1:01 |
| 4 | 34.4 | 4566 | 45 | 7 | 0 | 0 | A*2:01 |
| 5 | 9190.2 | 13567 | 3456 | 6789 | 9088 | 0 | A*1:01,A*2:01,B*9:02,C*10:01,DR*56:01 |
| 6 | 0 | 0 | 0 | 0 | 0 | 0 | |
| …… | | | | | | | |
我嘗試像這樣之前的腳本
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example",
Add Rows( 2 ),
New Column( "A*1:01", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 50000] ) ),
New Column( "A*2:01", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 50000] ) ),
New Column( "B*9:02", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 50000] ) ),
New Column( "C*10:01", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 50000] ) ),
New Column( "DR*56:01", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 50000] ) ),
//get wanted columns. Assumes that IMC columns start from column 1 and all IMC columns are one after another
colNames = dt << Get Column Names("String");
For(i = N Items(colNames), i > 3000 , i--,
);
//new column with IMC with value 1
dt << New Column( "Ag", Character,
<< Set Each Value(
rowValues = dt[Row(), 0][1::N Items(colNames)]; //get values of row as matrix
colIndex = Contains(rowValues, 1); //get index of
If(colIndex > 0, //handle
colNames[colIndex], //get column name with the index
""; //when no 1 found use ""
);
);
);您能更正我的腳本嗎,謝謝!
另外,我可以使用矩陣嗎,因為我需要產生180列的「新列」。
最好的,
資料混合與清理回覆:取得具有特定截止值的列名稱謝謝你,賈莫。這是工作!
回覆:取得具有特定截止值的列名稱這是生物學無法比擬的。
回覆:取得具有特定截止值的列名稱這是某種腳本,我仍然需要猜測正確的規則,所以我不知道它是否做了它應該做的事情
Names Default To Here(1);
dt = Open("$DOWNLOADS/Examples_get column name_edit.jmp");
// fix data
For Each({colname}, dt << Get Column Names("Character", "String"),
If(colname == "Alphabet",
break();
);
Column(dt, colname) << Set Data Type("Numeric") << Set Modeling Type("Continuous");
);
dt << Delete Columns("get name and value");
dt << New Column("R", Numeric, Ordinal, Formula(Row()));
dt_stacked = dt << Stack(
columns(
:"DOA1*01:01,DOB1*01:01_DO1"n, :"DOA1*02:01,DOB1*01:01_DO1"n,
:"DOA1*03:01,DOB1*01:01_DO1"n, :"DOA1*02:01,DOB1*02:01_DO2"n,
:"DOA1*01:05,DOB1*02:01_DO2"n, :"DOA1*04:03,DOB1*03:01_DO3"n,
:"DOA1*06:01,DOB1*04:01_DO4"n, :"DOA1*05:01,DOB1*03:01_DO7"n
),
Source Label Column("Label"),
Stacked Data Column("Data"),
Output Table("stacked")
);
rows_to_delete = dt_stacked << Get Rows Where(:Data <= 1000);
dt_stacked << Delete Rows(rows_to_delete);
dt_stacked << New Column("Match", Numeric, Nominal);
For Each Row(dt_stacked,
alphs = Words(:Alphabet, ",");
temp_label = Regex(:Label, "(\d\*)", "", GLOBALREPLACE);
retval = 0;
For Each({alph}, alphs,
If(Contains(temp_label, alph),
retval = 1;
break();
);
);
:Match = retval;
);
rows_to_delete = dt_stacked << Get Rows Where(:Match == 0);
dt_stacked << Delete Rows(rows_to_delete);
dt_stacked << New Column("NewStr", Character, Nominal, Formula(
:Label || " (" || Char(:Data) || ")"
));
Summarize(dt_stacked, rs = By(:R));
fixed_rs = Transform Each({r}, rs, Num(r));
vals = Associative Array();
For Each({r}, fixed_rs,
t = dt_stacked << Get Rows Where(:R == r);
vals[r] = Concat Items(dt_stacked[t, "NewStr"], ",");
);
Close(dt_ stacked);
new_col = dt << New Column("Res", Character, Nominal, Formula(
If(Contains(vals, :R),
vals[:R]
,
""
);
));
dt << run formulas;
new_col << Delete Formula;
</CODE></P>
<P> </P></LINGO-BODY><LINGO-SUB id="lingo-sub-781655" slang="en-US" mode="CREATE">回覆:取得具有特定截止值的列名稱</LINGO-SUB><LINGO-BODY id="lingo-body-781655" slang="en-US" mode="CREATE"><P>為什麼 DOA1*0x 與 DOx 不符?</P></LINGO-BODY><LINGO-SUB id="lingo-sub-781574" slang="en-US" mode="CREATE">回覆:取得具有特定截止值的列名稱</LINGO-SUB><LINGO-BODY id="lingo-body-781574" slang="en-US" mode="CREATE"><P>謝謝 Jarmo,我想附上與我想要在這裡執行的操作相容的文件。我想將由 DOA 和 DO 組成的字母列與 DOA1*0x:0x,DOB1*0x:0x_DOx 的每一列相符。 DOA0x 與 DOA1*0x 相符(「:」後不包含),DOx 或 DOB1*Ox 與 DOx 相符。它們的值都必須大於 1000 才能顯示在結果欄中。我無法像你所說的那樣糾正現有的公式。先感謝您!</P></LINGO-BODY><LINGO-SUB id="lingo-sub-781510" slang="en-US" mode="CREATE">回覆:取得具有特定截止值的列名稱</LINGO-SUB><LINGO-BODY id="lingo-body-781510" slang="en-US" mode="CREATE"><P>我的腳本處理了您提供的情況。根據實際問題,腳本可能需要完全重寫或可能只需要一些小的修改。</P></LINGO-BODY><LINGO-SUB id="lingo-sub-781509" slang="en-US" mode="CREATE">回覆:取得具有特定截止值的列名稱</LINGO-SUB><LINGO-BODY id="lingo-body-781509" slang="en-US" mode="CREATE"><P>此外,如果感興趣的字母表中的列超過 1,則腳本不會運行。您對此有何建議?</P><P> </P><P>謝謝你!</P></LINGO-BODY><LINGO-SUB id="lingo-sub-781508" slang="en-US" mode="CREATE">回覆:取得具有特定截止值的列名稱</LINGO-SUB><LINGO-BODY id="lingo-body-781508" slang="en-US" mode="CREATE"><P>查看表的開始和結束會有所不同(開始 A*1 和結束 A1),因此您必須將這些「額外」鍵新增至關聯數組以執行比較並稍後處理重複項。</P></LINGO-BODY><LINGO-SUB id="lingo-sub-781507" slang="en-US" mode="CREATE">回覆:取得具有特定截止值的列名稱</LINGO-SUB><LINGO-BODY id="lingo-body-781507" slang="en-US" mode="CREATE"><P>謝謝您的建議。如果我想匹配“:”之前的第一個單詞,它應該是這樣</P><PRE><CODE class=" language-jsl">alph = Word(1, colname, ":");
如果我想匹配“_”之後的最後一個單詞,它應該是這個
alph = Word(-1, colname, "_");
如果我需要同時匹配“:”之前和“_”之後怎麼辦?在我加入為上述每個腳本運行的腳本後,我無法管理重複的腳本(完全相同的事情)。
謝謝
回覆:取得具有特定截止值的列名稱這些「字母」是如何決定的?它們是最後一個“_”之後的所有內容嗎?如果是這種情況,您應該能夠對我的腳本進行非常細微的修改,並採用最後一個單字而不是第一個單字並使用不同的分隔符,因此這部分需要稍微修改
alph = Word(1, colname, "*");
回覆:取得具有特定截止值的列名稱太感謝了。這個腳本確實有效。不過,很抱歉我的原始數據比這更複雜。感興趣的字母表有多個以“,”(A1、B9)分隔的“字母”和“數字”作為附件。如何取得與感興趣的字母列和列名稱相關的名稱和值列。

感謝您的協助。
回覆:取得具有特定截止值的列名稱如果腳本編寫為使用名為“No”的列運行,後面跟著數字列。您提供的資料表除了數字之外還有 2 個字元列。如果刪除「感興趣的字母表」和「取得名稱和值」列,然後執行腳本,則它可以正常運作。
您應該能夠輕鬆更改腳本以補償額外的列。在開始檢索列名之前在腳本中刪除它們,或者在處理 For Each 之前從列名清單中刪除它們應該可行。
回覆:取得具有特定截止值的列名稱最有可能做吉姆建議的事情更快更容易,但是你可以用我演示的方法做這樣的事情
Names Default To Here(1);
dt = Open("$DOWNLOADS/Examples_get column name_by cutoff.jmp", invisible);
Summarize(dt, alphs = By(:"Alphabet of interest"n));
aa = Associative Array(alphs, Repeat({{}}, N Items(alphs)));
collist = dt << Get Column Names("String");
For Each({colname}, collist,
alph = Word(1, colname, "*");
If(Contains(aa, alph),
Insert Into(aa[alph], colname);
Column(dt, colname) << Set Data Type("Numeric") << Modeling Type("Continuous");
);
);
str_template = "^col^ (^val^)";
newcol = dt << New Column("getname", Character, Nominal, Formula(
cols = aa[:"Alphabet of interest"n];
vals = dt[Row(), aa[:"Alphabet of interest"n]];
valid_idx = Loc(vals > 1000);
If(N Items(valid_idx) > 0,
res = {};
For Each({{col, val}}, Across(cols[valid_idx], vals[valid_idx]),
Insert Into(res, Eval Insert(str_template));
);
Concat Items(res, ", ");
,
""
);
));
dt << run formulas;
newcol << delete formula;
dt << show window(1);

回覆:取得具有特定截止值的列名稱謝謝你,吉姆,但這不起作用。請參閱附件。
回覆:取得具有特定截止值的列名稱
非常感謝您,我想澄清這一點。我有另一列感興趣的列作為“感興趣的字母表”,我想獲取所有值> 1,000 的列的名稱和值,並且所有列都與感興趣的列字母表匹配。
謝謝你!
回覆:取得具有特定截止值的列名稱這是一種可能有助於處理大量列的替代方法
Names Default To Here( 1 );
dt = Open("$DOWNLOADS/Examples_get column name_by cutoff.jmp");
colnames = Remove( dt << Get Column Names( "String" ), 1 ); // drop No column
// Fix data and modeling types
For Each({colname}, colnames,
Column(dt, colname) << Data Type("Numeric") << Modeling Type("Continuous");
);
dtStack = dt << Stack(
columns( colnames ),
Source Label Column( "ColName" ),
Stacked Data Column( "Value" ),
Output Table( "The Stack" )
);
dtStack << select where( :value <= 1000 );
dtStack << delete rows;
dtStack << delete columns( Value );
dtSplit = dtStack << Split(
Split By( :ColName ),
Split( :ColName ),
Group( :No ),
Output Table( "Split of The Stack by ColName" ),
Sort by Column Property
);
close( dtStack, nosave );
colnames = Remove( dtSplit << Get Column Names( "String" ), 1 );
dtSplit << Combine Columns(
delimiter( "," ),
columns( colnames ),
Column Name( "Get Name" )
);
dtSplit << delete columns( colnames );
dt << Update( With( dtSplit ), Match Columns( :No = :No ) );
Close( dtSplit, nosave );回覆:取得具有特定截止值的列名稱您希望如何提取它們?我的解決方案是否建立了新列,其中列名稱為由 , 和空格分隔的字串?

您希望按列而不是按行檢查值嗎?還是別的什麼?
編輯:
如果您只想要不同的列列表,我必須知道如何過濾它。如果您只想要所有列,請刪除Remove()函數
Names Default To Here(1);
dt = Open("$DOWNLOADS/Examples_get column name_by cutoff.jmp", invisible);
colnames = dt << Get Column Names("String");
For Each({colname}, colnames,
Column(dt, colname) << Data Type("Numeric") << Modeling Type("Continuous");
);
For(i = 1, i < 100, i++,
newcol = dt << New Column(Hex(i), Numeric, Nominal, Values(J(1, N Rows(dt), Random Normal()*1000)));
);
colnames = dt << Get Column Names("String");
newcol = dt << New Column("getname", Character, Nominal, Formula(
valid_idx = Loc(dt[Row(), colnames] > 1000);
If(N Items(valid_idx) > 0,
Concat Items(colnames[valid_idx], ", ")
,
""
);
));
dt << run formulas;
newcol << delete formula;回覆:取得具有特定截止值的列名稱您好,Jarmo,您是否知道如何提取每個列名稱(示例中的 getname 列)超過截止值(如果我有 50 個欄位)的值
回覆:取得具有特定截止值的列名稱您必須開啟表,修復列,然後執行建立新列的部分
Names Default To Here(1);
dt = Open("$DOWNLOADS/Examples_get column name_by cutoff.jmp", invisible);
colnames = Remove(dt << Get Column Names("String"), 1); // drop No column
// Fix data and modeling types
For Each({colname}, colnames,
Column(dt, colname) << Data Type("Numeric") << Modeling Type("Continuous");
);
newcol = dt << New Column("getname", Character, Nominal, Formula(
valid_idx = Loc(dt[Row(), colnames] > 1000);
If(N Items(valid_idx) > 0,
Concat Items(colnames[valid_idx], ", ")
,
""
);
));
dt << run formulas;
newcol << delete formula;
我強烈建議您查看JMP 幫助中的腳本指南
回覆:取得具有特定截止值的列名稱嗨,賈莫,
感謝您的幫助,但老實說,如下面的附件所示,我無法像您一樣運行腳本。當我檢查如下所示的腳本(命令+1)時。感謝您的協助。
dt = New Table("Example",
Add Rows(20000),
invisible
);
colcount = 200;
For(i = 1, i <= colcount, i++,
newcol = dt << New Column(Char(i), Numeric, Continuous, Formula(
Random Normal() * 1000
));
dt << run formulas;
newcol << delete formula;
);
start = Tick Seconds();
colnames = dt << Get Column Names("String");
newcol = dt << New Column("getname", Character, Nominal, Formula(
valid_idx = Loc(dt[Row(), colnames] > 1000);
If(N Items(valid_idx) > 0,
Concat Items(colnames[valid_idx], ", ")
,
""
);
));
dt << run formulas;
newcol << delete formula;
wait(0);
end = Tick Seconds();
show(end - start);
/*:
end - start = 0.683333333348855;
回覆:取得具有特定截止值的列名稱我的腳本使用值建立新列“getname”

使用您的數據,將列修復為數字(並刪除“無列”)後

回覆:取得具有特定截止值的列名稱嗨,賈莫,
太感謝了。但結果是“end - start = 0.03333333333255723;”那不是新桌子。您能提供更多解決方案嗎?請給我看一下 JMP 上的以下資料表。
謝謝
回覆:取得具有特定截止值的列名稱這可能足夠快
Names Default To Here(1);
// Create a sample data table
dt = New Table("Example",
Add Rows(20000),
invisible
);
colcount = 200;
For(i = 1, i <= colcount, i++,
newcol = dt << New Column(Char(i), Numeric, Continuous, Formula(
Random Normal() * 1000
));
dt << run formulas;
newcol << delete formula;
);
start = Tick Seconds();
colnames = dt << Get Column Names("String");
newcol = dt << New Column("getname", Character, Nominal, Formula(
valid_idx = Loc(dt[Row(), colnames] > 1000);
If(N Items(valid_idx) > 0,
Concat Items(colnames[valid_idx], ", ")
,
""
);
));
dt << run formulas;
newcol << delete formula;
wait(0);
end = Tick Seconds();
show(end - start);回覆:取得具有特定截止值的列名稱嗨吉姆,
感謝您的協助。但是,我有 180 列和 20000 行的不同單詞,我無法將它們全部放入以下腳本中。您能給我更多建議嗎?
謝謝
回覆:取得具有特定截止值的列名稱這是我將如何處理這個問題

names default to here(1);
dt = New Table( "Example",
Add Rows( 6 ),
New Column( "A*1:01",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[10.67, 0, 9040.2999999999993, 34.399999999999999, 9190.2000000000007, 0
]
)
),
New Column( "A*2:01",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [0, 0, 345.30000000000001, 4566, 13567, 0] )
),
New Column( "B*9:02",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [9520.2299999999996, 0, 345.89999999999998, 45, 3456, 0] )
),
New Column( "C*10:01",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [15000.1, 0, 999.89999999999998, 7, 6789, 0] )
),
New Column( "DR*56:01",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [90.560000000000002, 0, 345, 0, 9088, 0] )
),
New Column( "DP*07_G",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [40.890000000000001, 9.5600000000000005, 10.5, 0, 0, 0] )
)
);
dt << New Column( "Get Name",character);
colNames = dt << get column names( continuous,string );
For Each Row(
theList = {};
For Each( {col, i}, colNames,
If( As Column( col ) > 3000,
Insert Into( theList, col )
)
);
:Get Name = Concat Items( theList, "," );
);