【发布时间】:2019-09-14 10:36:39
【问题描述】:
在 R 中,data.table 库 dcast() 可以将数据集从宽形转换为长形,我如何在 googlespreadsheet 中做到这一点?
从此格式:
| JAN | FEB | MAR
----------+------------+------------+-----------
Product 1 | 1 | 2 | 3
Product 2 | 4 | 5 | 6
Product 3 | 7 | 8 | 9
将其转换为这种格式:
Date| Product | Qty
-----------+-----------+----
JAN | Product 1 | 1
FEB | Product 2 | 4
MAR | Product 3 | 9
JAN | Product 2 | 4
FEB | Product 1 | 2
JAN | Product 3 | 7
MAR | Product 2 | 6
FEB | Product 3 | 8
MAR | Product 1 | 3
我们有什么解决方案来实现这一点吗?
【问题讨论】:
-
您能解释一下从输入值中检索输出值的逻辑吗?我无法理解为什么
4被使用了 2 次以及输出行的顺序。您的问题逻辑与this thread 不同吗?如果我误解了您的问题,我深表歉意。 -
对不起 tanaike ,它只是一个错字 .FEB Product 2 应该是 5 。只想重塑数据格式,如 R
dcast()otmelt()函数 -
感谢您的回复。我提出了一个示例脚本作为答案。你能确认一下吗?如果我误解了您的问题并且结果不是您想要的,我深表歉意。顺便说一句,如果可以的话,你能用你想要的正确输出来更新你的问题吗?
标签: google-apps-script google-sheets reshape unpivot melt