JMP 按 JSL 中的列名列表製表你好,
我有表格,我想按“學生”列、“主題”列和“班級”列將其製成表格,但數據中沒有必要提供“主題”列和“班級”列。
如果它有“主題”列但沒有“班級”列,那麼它應該按“學生”列和“主題”列製表。
如果它有“類”列但沒有“主題”列,那麼它應該按“學生”列和“類”列製表。
如果它包含所有列,那麼它應該按所有三列製表。 下面是一些例子。
示例 1:(它同時包含“主題”列和“類”列)
輸入:
| 班級 | 學生 | 分數 | 主題 |
| 1個 | A | 10 | 數學 |
| 2個 | A | 15 | 科學 |
| 3個 | A | 12 | 科學 |
| 1個 | 乙 | 15 | 數學 |
| 2個 | 乙 | 12 | 科學 |
輸出:
| 班級 | 學生 | 主題 | 最大(分數) |
| 1個 | A | 數學 | 10 |
| 2個 | A | 科學 | 15 |
| 3個 | A | 科學 | 12 |
| 1個 | 乙 | 數學 | 15 |
| 2個 | 乙 | 科學 | 12 |
示例 2:(它有“Class”列但沒有“subject”列)
輸入:
| 班級 | 學生 | 分數 |
| 1個 | A | 10 |
| 2個 | A | 15 |
| 3個 | A | 12 |
| 1個 | 乙 | 15 |
| 2個 | 乙 | 12 |
輸出:
| 班級 | 學生 | 最大(分數) |
| 1個 | A | 10 |
| 2個 | A | 15 |
| 3個 | A | 12 |
| 1個 | 乙 | 15 |
| 2個 | 乙 | 12 |
示例 3:(它有“主題”列但沒有“類”列)
輸入:
| 學生 | 分數 | 主題 |
| A | 10 | 數學 |
| A | 15 | 科學 |
| A | 12 | 科學 |
| 乙 | 15 | 數學 |
| 乙 | 12 | 科學 |
輸出:
| 學生 | 主題 | 最大(分數) |
| A | 數學 | 10 |
| A | 科學 | 15 |
| 乙 | 數學 | 15 |
| 乙 | 科學 | 12 |
請幫我解決這個問題。
謝謝
回复:JMP 按 JSL 中的列名列表製表謝謝你@tsnelson回复:JMP 按 JSL 中的列名列表製表這是你想要的???
names default to here(1);
dt=current data table();
// The list of columns to look for
theList={"Class","Student","Subject", "xxxxxx","xxxxxx"};
allColList = dt << get column names(string);
// Remove any columns from theList that are not in the data table
For(i=n items(theList),i>=1, i--,
If(n rows(loc(allColList,theList[i]))==0,
remove from(theList,i,1)
)
);
// Run the tabulate
Tabulate(
Show Control Panel( 0 ),
Add Table(
Column Table( Analysis Columns( :Marks ), Statistics( Max ) ),
Row Table( Grouping Columns( eval(theList) ) )
)
);
如果不同的目標列扮演分組列以外的角色,您將需要針對不同的所需輸入語法開發代碼。
回复:JMP 按 JSL 中的列名列表製表@txnelson我有 5 列,例如“類”列和“主題”列,它們可以存在於數據中,也可以不存在。 現在要製表,我必須給出 IF 條件的所有排列,每個排列都有單獨的製表代碼。 它會讓代碼變得過於凌亂。
相反,如果我們可以使用單個 Tabulate 函數來做到這一點,我們在其中給出所有列的列表,它將只採用數據中可用的那些列。
謝謝回复:JMP 按 JSL 中的列名列表製表將 Tabulate 代碼壓縮為一組代碼,會使代碼複雜得多。
當你說你有更多的專欄時,你能進一步解釋嗎?
回复:JMP 按 JSL 中的列名列表製表@txnelson感謝回复。
我們可以用單個製表腳本塊解決這個問題嗎,因為在我的原始數據集中我有很多這樣的列。回复:JMP 按 JSL 中的列名列表製表在示例數據表上運行 3 個場景中的每一個,將每次運行的每個腳本保存到腳本窗口中。然後分別取相應的腳本,在指定位置放到下面的腳本中
names default to here(1);
dt= current data table();
colNames = dt << get column names(string);
// Here is the IF() structure to add in the tabulate code to
If( N Rows(loc(colNames, "Subject" ) ) > 0 & N Rows(loc(colNames, "Class" ) ) > 0,
// Add in the tabulate code that has Student, Subject and Class
,
N Rows(loc(colNames, "Subject" ) ) > 0,
// Add in the tablulate code that has just Student and Subject
,
N Rows(loc(colNames, "Class" ) ) > 0,
// Add in the tablulate code that has just Student and Class
);