表格加入的具体情况所有,
我有一个特定的问题要解决,虽然我手动地在一小部分原始数据上成功地解决了它,但我无法对整个庞大的数据集做到这一点。
所以,这就是问题所在。我有两张桌子。
第一个表 - 在一些工具上完成的一些测量
| 工具 | 日期 | 测量 |
A001 | 2017年1月1日 | 0.005 |
| B006 | 2017年2月2日 | 0.003 |
第二个表 - 在相同工具上替换某些部件的历史记录:
| 工具 | 日期 | 部分S / N. |
| A001 | 2016年1月1日 | 1234567 |
| B006 | 2016年2月2日 | 0987654 |
| A001 | 2016年12月29日 | 1234568 |
我想看到的是,每个工具的测量结果取决于安装的零件年龄。作为结果表,我需要的是与测量相同的表,只有少量添加的列:
| 工具 | 日期 | 测量 | 已安装的部分 | 安装日期 | 部分年龄 |
A001 | 2017年1月1日 | 0.005 | 1234568 | 2016年12月29日 | 4天 |
| B006 | 2017年2月2日 | 0.003 | 0987654 | 2016年12月29日 | 365天 |
基本上,我手动为一个工具做了这个 - 只是创建了一个列,并用耳朵填充;最简单的更换日期。然后向下移动测量表,直到下次安装的日期 - 从那里填充相同的列到新的安装日期结束,然后进一步移动.... 乏味。
我需要以某种方式自动化,但我甚至无法开始绕过它。
因此,对于测量表中的每一行,我需要在零件更换表中找到一条线,该线具有匹配的工具,并且安装日期早于所考虑的线的日期。然后我需要获取该序列号,该日期并将其放入测量表中。然后很容易计算零件年龄。有些部分安装日期很久以前它们都没有被这两个表覆盖,所以我可能有很多缺失的值。
有人可以用方法帮我,也许有点启动脚本吗?
非常感谢!
Re:表加入的具体情况伊恩
你确定吗?
Loc(replacedOn[rowsForThisTool] == latestReplacementDate);
是正确的语法?
我的意思是我得到你想要在这里做的事情,但它给了我错误和语法帮助说它应该是Loc(x,y) - 给你x中的所有索引,它等于y。仅等于,不是任何逻辑陈述。任何想法如何重写这句话?
谢谢!
Re:表加入的具体情况伊恩
你觉得这样的事情会起作用吗?
currentReplacementDate = Max(replacedOn[rowsForThisTool]<thisDate);
thisDate类似于thisTool:
thisDate = currentMeasDate[t];
和currentMeasDate只是测量表的日期。
现在,由于这两个表是由不同的系统生成的,因此日期格式不同(y / m / d vs m / d / y hh:mm:ss或类似的东西)。我是否需要以某种方式将一个翻译成另一个,否则它将自动完成?
Re:表加入的具体情况伊恩
非常感谢这么详细的答案。
关于这个的快速问题:
latestReplacementDate = Max(replacedOn[rowsForThisTool]);
随着测量的进行,定期更换零件。所以我不仅需要找到最新的,我需要在测量过程中找到工具上的零件,简单的最新版本不会。基本上,我需要找到最新的替换日期,以便测量日期大于repplacedOn日期。关于如何以最有效和优雅的方式做到这一点的任何建议?我每个月左右都会有数十种工具和部件更换的日常数据,因此效率更高 - 到目前为止我只能提出另一个循环比较日期。
如果您有一个更优雅的解决方案,我会非常感激。
Re:表加入的具体情况你可以尝试这样的事情:
NamesDefaultToHere(1);
dt1 = DataTable("Measurements On Tools");
dt2 = DataTable("Parts Replaced");
// Get a list of the tools on which measurements were made
toolsUsed = Column(dt1, "Tool") << getValues;
// Get a list of the tools which had one or more parts replaced
toolsWithReplacedPart = Column(dt2, "Tool") << getValues;
// Get the corresponding replacement dates
replacedOn = Column(dt2, "Date") << getValues;
// And the corresponding part numbers
partSN = Column(dt2, "Part SN") << getValues;
// Make a new vector and a list that will be populated via the loop below
dates = J(NRow(dt1), 1, .);
parts = {};
// Loop over each measurement made
for(t=1, t<=NItems(toolsUsed), t++,
thisTool = toolsUsed[t];
// Find the rows in dt2 in which this tool is referenced
rowsForThisTool = Loc(toolsWithReplacedPart, thisTool);
// Find the latest date on which a part was replaced and store it
latestReplacementDate = Max(replacedOn[rowsForThisTool]);
dates[t] = latestReplacementDate;
// Identify the new part used and store it
rowForLatestPart = Loc(replacedOn[rowsForThisTool] == latestReplacementDate);
newPart = partSN[rowsForThisTool][rowForLatestPart];
InsertInto(parts, newPart);
);
// Add the new columns to dt1
dt1 << newColumn("Last Installed Part", Character, Values(parts));
dt1 << newColumn("Installed Date", Numeric, Continuous, Values(dates), Format( "m/d/y", 12 ));
dt1 << New Column( "Age of Part", Numeric, Continuous, Format( ":day:hr:m", 14 ), Formula( :Date - :Installed Date ));
代码很冗长,试图显示所使用的逻辑。请记住,这没有测试,并且可以得到很大改进:例如,不需要'<< getValues()'(至少在JMP 13中)。
Re:表加入的具体情况这正是我所做的。看起来很好,直到我发布。
Re:表加入的具体情况您可以通过单击表格图标来插入表格
| 11 |
44 |
222 |
| 333 |
444 |
66 |
| 88 |
55 |
99 |
Re:表加入的具体情况顺便说一句,抱歉丑陋的桌子 - 在编辑窗口他们看起来不错。找不到任何方法可以返回编辑主题以使表格更具可读性。它甚至可能吗?
谢谢!