您好,我是Jmp的新手,正在使用腳本嘗試重新排列數據集。目前,我有一個數據集,如下所示:
| ID | 實驗室 | 實驗值 | 實驗室日期和時間 | 藥物 |
| 一個 | 汞 | 12 | 16-10-5上午6:00 | 泰諾 |
| 一個 | 鉻 | 1個 | 16-10-5上午6:00 | 泰諾 |
| 一個 | ķ | 4 | 16-10-5上午6:00 | 泰諾 |
| 乙 | ķ | 3.7 | 02/11/6 4:00上午 | 阿司匹林 |
| 乙 | ķ | 4.5 | 02/11/6上午7:00 | 阿司匹林 |
| 乙 | 鉻 | 1.2 | 02/11/6上午7:00 | 阿司匹林 |
| 乙 | 汞 | 14 | 02/11/6上午7:00 | 阿司匹林 |
| C | 鉻 | 1.5 | 09-1-15上午6:30 | 維生素D |
| C | 汞 | 12 | 09-1-15上午6:30 | 維生素D |
| C | 汞 | 9 | 2009年1月15日上午9:30 | 維生素D |
我希望每個ID都是一行,每個實驗室都有列。對於任何ID,可能會有不同實驗室的重複,但是我想保留每個實驗室的所有值,並將它們放在單獨的列中。我當時在考慮按ID和實驗室排序後再做一個計數變量,這樣我就可以合併並創建一個變量,即Hgb1,Hgb2,但是我不知道該怎麼做。我在拍照時也不知道如何轉置。
| ID | 汞1 | 實驗室日期和時間 | 汞2 | 實驗室日期和時間 | 鉻1 | 實驗室日期和時間 | 鉻2 | 實驗室日期和時間 | K1 | 實驗室日期和時間 | K2 | 實驗室日期和時間 | 藥物 |
| 一個 | 12 | 16-10-5上午6:00 | | | 1個 | 16-10-5上午6:00 | | | 4 | 16-10-5上午6:00 | | | 泰諾 |
| 乙 | | | | | | 02/11/6上午7:00 | | | 3.7 | 02/11/6 4:00上午 | 4.5 | 02/11/6上午7:00 | 阿司匹林 |
我將不勝感激任何幫助。
謝謝!!!
這花了很多時間和一些腳本,但是我認為這至少可以為您提供一個良好的開端。 我不確定您真正想使用的藥物值是什麼,所以我將它們添加到每個實驗室分組中。...您可能想要更改它。 另外,JMP不喜歡具有相同名稱的列,因此我為名稱保留了唯一的名稱

names default to here(1);
dt=current data table();
// Add a rowNum column to capture the original data table order
dt << New Column("rowNum", formula(Row()));
dt:rowNum << delete formula;
// Order the data so that a count column can be calculated
dt << sort(by(:Lab, :ID), order(ascending,ascending),replace table(1));
// Add the count value, to count the number of duplicate labs for each ID
dt << new column("count", formula(If( Row() == 1, mycount = 1 );
If( Lag( :ID ) == :ID & Lag( :Lab ) == :Lab,
mycount++,
mycount = 1
);
mycount;));
// Split the data into columns
dtSplit = dt << Split(
Split By( :Lab, :count ),
Split( :Lab Value, :Lab date and time, :Medication ),
Group( :ID ),
Remaining Columns( Drop All ),
Sort by Column Property
);
// Clean up the original data table
dt << sort( by(:rowNum),order(ascending), replace table(1));
dt << delete columns({"count", "rowNum"});
// Order the columns
// Get the list of columns that start with "Lab Value", which
// will be used to order the columns based on them
labValueList = {};
for(i=1,i<=ncols(dtSplit),i++,
If(uppercase(left(column(i)<<GET name=""></GET>非常感謝!一旦我將我的ID變量設為不是表達式,就可以完美工作了!