您好,我是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变量设为不是表达式,就可以完美运行!