使用转置将数据子集从一个表移动到第二个表的列很抱歉再次发布此内容。我在这里发布了一些我工作流程的片段,并进行了屏蔽,以寻求帮助,但我仍然在努力。我很难检查回复,因为我在 StackOverflow 上有过不愉快的经历,被人无缘无故地大喊大叫。我相信伤疤会随着时间的推移而愈合。无论如何,我会在这里,最终会得到你的回复。
说到技术要点:
我正在尝试将一些样本的运行日期(假设在项目的实验室部分一切顺利,每个样本应该在 3 个不同的场合运行,而我当时不在)复制到清单文件的三个单独的列中,该文件跟踪我们项目的持续元数据,根据我收集的信息,每个列都是一个数据收集实例。有多个捐赠者,每个捐赠者都有一个捐赠者 ID,数据中有一些冗余,比如仪器上“同一数据点”的多个收集通道(取决于您如何看待它),但我认为应该就是这样。
这是我一直在尝试使用的伪代码,到目前为止还很粗糙。我不知道为什么。我不是经验丰富的计算机科学家、开发人员或软件工程师。任何帮助我都感激不尽。
DataTypes:
(associative array) DonorID{
(key) Month1: (value) date1 (empty at start)
(key) Month2: (value) date2 (empty at start)
(key) Month3: (value) date3 (empty at start)
}
find unique donor IDs in data
for each donor ID{
get (i.e. subset) data keyed on donor ID;
for Month in 1, 2, 3 (strings){
if no date in donorID associative array{
add date from data;
}else if date already{
is the date in the data table cell the same as in the associative array entry?
if yes, do nothing (indicates different target channel)
if no, ping user
Multiple run dates for same data point is a problem.
}
}
}
Copy from data to manifest:
loop over DonorID associative array:
for each donorID:
in Month 1, 2, or 3:
add date1 2 or 3 to "Actual Month [1, 2, or 3] Stability Test Date" in manifest
donorID is still row identifier
date (1, 2, or 3) is now column identifier
数据混合和清理回复:使用转置将数据子集从一个表移动到第二个表的列现在我正在尝试将数据/日期分配给具有正确 ID 的行中的清单文件:
... );
//write(LBCM_array);
dt_manifest << Get Rows Where(dt_manifest:ID Number for Updating Table == ID)[:Actual Data 1 Date] = data_array["data1"];
//repeat for data 2 & 3
);
真的,作为一个初学者,我仍然不知道如何从 JSL 开始,所以我得到了错误
["data1" => {}, "data2" => {}, "data3" => {}]
attempting to assign to an object that is not an L-value in access or evaluation of 'Assign' , dt_manifest << Get Rows Where(
dt_manifest:ID Number for Updating Table == ID
)[:Actual Data 1 Date] = /*###*/data_array["data1"] /*###*/我不知道这是什么意思。
谢谢,
麦克风
回复:使用转置将数据子集从一个表移动到第二个表的列以下对我有用...
Names Default To Here( 1 );
dt_data = Open("...");
Summarize( dt_data, IDs = by(dt_data:ID)); //this finds all the unique donor IDs in the data file, which we will need
//First, populate the temporary data structure--associative array--from the data file which we will then copy over to the manifest data file.
For(i = 1, i <= N Items(IDs), i++,
ID = num(IDs[i]); //the type conversion here is important, or else a key-value call in the associative array below doesn't work
data_array = Associative Array( {"data1", "data2", "data3"}, {{}, {}, {}} ); //it appears in the print statements we get 3 copies, indicating this loop works
For( data = data_array << First, !Is Empty( data ), data = data_array << Next( data ), //looping through data_array's keys is clunky but done this way in JMP
data_array[data] = dt_data:Run date[dt_data << Get rows Where(:ID == ID & :Timepoint == data)]
);
);除了现在我在 data_array 中有每个数据(日期时间点)条目的多个副本。 我想知道如何清理干净,只为 data_array 中的每个日期/数据制作一份副本?
我一直在尝试使用 if 语句,使用 As Date() 语句来比较和格式化日期以进行比较和输入,以确保我们只获得一个唯一值。 但到目前为止,这给我带来了问题(即数组变成错误或再次为空)。
不过,我对到目前为止的进展感到非常满意。
@txnelson : 抱歉,我喜欢你的方法并感谢你的帮助,但你会注意到我能够在没有你的索引“k”技术的情况下随意摆弄它
。 (我想知道当有多个相同值的日期时你的方法如何公平,这就是我的情况?)
@brady_brady :请注意,我在适当的列调用之前实施了数据表标识符。 谢谢你教我这个基本概念;我对它非常好奇,谷歌搜索到现在都没有结果。
麦克风
回复:使用转置将数据子集从一个表移动到第二个表的列大家好。 实际上,这一次我正在取得进步,而不是在不知道该往哪个方向前进的情况下被困在某件事上。
目前我的一个键/值对不适合,所以我从我的一个数组调用中得到了不正确的结果。 我正在尝试对此进行调试,以便我可以将数据表正确地子集/过滤到我想要传输到关联数组的内容。
非常感谢您的帮助。
麦克风回复:使用转置将数据子集从一个表移动到第二个表的列谢谢你,布雷迪。 这一切对我来说都很有意义。
看起来其中一些实际上是我代码中的问题。 我已经解决了他们并且正在前进。 我有新问题,一旦我弄明白了就会发布。
麦克风
回复:使用转置将数据子集从一个表移动到第二个表的列嗨,吉姆。 感谢您的答复。 你介意用人类英语解释你的代码是如何工作的吗? 我的解释是:所有ID唯一的行都放在theRows中。 然后,索引k被实例化。它在将运行日期添加到数据数组的循环内递增。在这个循环中,现在,而不是我以前拥有的,theRows 中的每个唯一值都用作索引来访问 :Run date,并将结果填充到数据数组中。
如果我研究得更久一点,这对我来说就有意义了。 乍一看不是太清楚。 不确定。 但是您确实在帖子末尾用一行结论进行了解释。
在我用我的代码中的真实变量替换所有被擦除的变量后,我得到错误:
invalid subscript (must be number or list of numbers) in access or evaluation of 'theRows[k]' , theRows[/*###*/k]
我不知道为什么。
我仍然很困惑,我将继续研究这段代码。 很奇怪,我在大学里上了相当多的编码课程,但我没有维护我的知识库,所以我想它可能会随着时间的推移而消失。
谢谢您的帮助!
迈克尔
PS:至于为什么使用关联数组:认为这将是一种有效的传输数据的方式,作为一个 JMP 初学者,在 Java/Python 方面有更多的经验。 您会推荐直接操作表格吗? 不过,到目前为止,我一直沿着这条路走,我想知道以这种方式完成手头的任务是否会很有趣。
回复:使用转置将数据子集从一个表移动到第二个表的列你好,
你写:
我现在的问题是这一行:
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data);
我看到了几个潜在的问题......一定要调查这些:
1):运行日期,如所写,指的是解释这行代码时当前数据表中的列。 从报错信息来看,在解释这行代码时,当前数据表中并没有名为“Run Date”的列。 我看到你开了两张桌子;始终确保目标表确实是当前表,如果由 JMP 决定使用哪个表。 您可以使用当前数据表命令强制任何您希望成为当前表的表:
dt1 = open("firstfile");
dt2 = open("secondfile");
Current Data Table (dt1); // sets first table current
Current Data Table (dt2); //sets second table current
不过,您不必让 JMP 来决定。 您可以使用表:列格式,如:
dt1:Run Date
2) 解决表货币问题后,您需要使用<< 获取行,其中 ( )消息,发送到适当的数据表,返回满足某些条件的行。 通常这些被用作索引,就像你的情况一样。 假设您要使用 dt1,则代码将显示为:
data_array[data] = dt1:Run Date[dt1 << Get rows Where(:ID == ID & :Timepoint == data)];
这条线做了 3 个工作:
1) 获取 dt1 中满足某些条件的行,将它们返回到向量中。 请注意,因为<< 获取行 where() message发送到dt1,可以理解::ID和:Timepoint也在dt1中。
2) 使用上面步骤 1 中返回的向量作为 dt1:Run Date 的索引,它是 dt1 中的 Run Date 列。 因为我们已经使用 dt1:Run Date 将运行日期显式限定为 dt1 表,所以 dt1 是否恰好是当前表并不重要。 完成第 2 步后,会从“运行日期”列返回一个值向量——正是我们想要的值。
3) 将上面步骤 2 中返回的运行日期值的向量分配为特定键的值,数据,在关联数组中,数据数组.
干杯,
布雷迪
回复:使用转置将数据子集从一个表移动到第二个表的列麦克风,
我对为什么要使用关联数组仍然有些迷惑,但无论如何,我相信下面的代码将移入数组,每个 ID 的 3 个测量行的日期值。我编造了一些数据,希望它们与您的数据布局相似。我只是根据您的陈述和代码使用情况进行猜测。

这是脚本。上面的数据表是在脚本的开头生成的,所以你的代码的内容,经过我的修改,在数据表生成下面。
Names Default To Here( 1 );
dt_data = New Table( "Example",
Add Rows( 6 ),
New Column( "ID", Character, "Nominal", Set Values( {"A", "A", "A", "B", "B", "B"} ) ),
New Column( "Run Date",
Numeric,
"Continuous",
Format( "m/d/y", 12 ),
Input Format( "m/d/y" ),
Set Values( [3692304000, 3694982400, 3697401600, 3700080000, 3702672000, 3705350400] )
),
New Column( "TimePoint", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., ., ., ., ., .] ) )
);
//dt_manifest = Open( "[filepath, no issues here]" );
Summarize( dt_data, IDs = by( :ID ) ); //this finds all the unique IDs in the data file, which we will need //[no issues here]
//First, populate the temporary data structure--associative array--from the data file which we will then copy over to the manifest file.
For( i = 1, i <= N Items( IDs ), i++,
ID = IDs[i];
theRows = dt_data << get rows where( :ID == ID );
data_array = Associative Array( {"data1", "data2", "data3"}, {{}, {}, {}} );
k=0;
For( data = data_array << First, !Is Empty( data ), data = data_array << Next( data ), //looping through data_array's keys is clunky but done this way in JMP
k++;
show( ID ); //just a check; works
data_array[data] = :Run date[theRows[k]];
//...continue with further code to transfer from LBCM_array to manifest
);
show(data_array);
);
代码的结果列在日志中
ID = "A";
ID = "A";
ID = "A";
data_array = ["data1" => 3692304000, "data2" => 3694982400, "data3" => 3697401600];
ID = "B";
ID = "B";
ID = "B";
data_array = ["data1" => 3700080000, "data2" => 3702672000, "data3" => 3705350400];
data_array 中的数字是运行日期的数值。
回复:使用转置将数据子集从一个表移动到第二个表的列大家好。 到目前为止,这是我的代码:
Names Default To Here( 1 );
dt_data = Open( "[filepath, no issues here]" );
dt_manifest = Open( "[filepath, no issues here]" );
Summarize( dt_data, IDs = by( :ID ) ); //this finds all the unique IDs in the data file, which we will need //[no issues here]
//First, populate the temporary data structure--associative array--from the data file which we will then copy over to the manifest file.
For( i = 1, i <= N Items( IDs ), i++,
ID = IDs[i];
data_array = Associative Array( {"data1", "data2", "data3"}, {{}, {}, {}} ); //it appears in the print statements we get 3 copies, indicating this loop works
For( data = data_array << First, !Is Empty( data ), data = data_array << Next( data ), //looping through data_array's keys is clunky but done this way in JMP
Write( ID ); //just a check; works
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data); //does not work
//...continue with further code to transfer from LBCM_array to manifest
);
);我已经擦洗它所以它是机密的(不用担心监视公司信息;))同时保留结构和信息(名称“a”名称,标签到标签)。
我现在的问题是这一行:
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data);
它抛出错误信息
.
Name Unresolved: Run date in access or evaluation of 'Run date' , :Run date/*###*/
In the following script, error marked by /*###*/
...
data_array[data] = :Run date/*###*/ <<WHERE></WHERE>
:Run date 是我的数据表(特别是 dt_data)中带有实验运行日期的数据列(标题)。 我正在尝试将这些传输到第二个文件,因为每个数据点都应该收集三次/三次,这就是为什么 data_array 在初始化时具有三个键和三个空值的原因。 这就是数据所在的位置,这个关联数组 (data_array)。 然后它被转移到 dt_manifest 但这是为了稍后,一旦这部分工作。
现在看来我无法在线访问
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data);
the appropriate selection of rows and columns I am interested in. 在这个时间点,问题陈述是否足够清楚,听众中的任何人都可以参与并提供解决方案或贡献,以了解如何以更语法(并且可能语义)正确的方式指定如何选择我的数据子集对(来自 data_dt)感兴趣?
不用担心转置问题。 我稍后会处理这个问题,老实说,一旦数据在 aa(关联数组)中,这应该很容易。 此时我还在学习如何操作行/列选择、数据表的子集等相关问题。
还有一点要注意:如果日期、数据和数组混合在一起看起来很奇怪,那很可能是因为我为数据列或相关数据实体的清理/匿名标题/标签选择了糟糕的名称,以保护我公司的秘密安全。 我会说,在整个过程中我仍然是新手,我宁愿为了安全起见而犯错。
我将继续从头开始解决这个问题。
非常感谢,
麦克风
回复:使用转置将数据子集从一个表移动到第二个表的列谢谢你,布雷迪。回复:使用转置将数据子集从一个表移动到第二个表的列你好,
欢迎来到社区! 很抱歉,您在寻求帮助时在其他板上有过负面经历。 尽管 JMP 用户社区是一个热情好客且乐于助人的地方,但也有一些“最佳实践”可以最大限度地提高您获得所需信息的机会。
问具体的问题,反之更笼统的问题,如果你能成功的话,这是一种可行的方法——尽管我确实意识到有时候一个人“不知道他不知道什么”。 发布大量伪代码可能会吓跑人们……如果您不能以其他方式提出您的问题,那么附上“之前”和“之后”文件以及屏幕截图将大有帮助,这样观众就会有具体的了解“开始”表(或文本数据)和“完成”表的示例。 在这种特殊情况下,这肯定会产生真正的影响。 如果您必须“清理”数据集,那很好(最好,真的)。 只要你试图说明的观点仍然存在,就很好。
如果您提出具体的、有针对性的问题并附上说明性文件和屏幕截图,那么这里的许多人很可能会跳出来提供帮助。 我能想到不止几个无法真正抗拒它的副手!
干杯,
布雷迪