拆分行并平均分配相应的值

时间:2018-06-13 08:56:51

标签: spotfire

我想将一个列中的某个组名拆分为两个不同的组名,并将它们的相应值平分。

以下是我尝试完成的一个简化示例:

enter image description here

我想分成两行,组名不同,行值平均分开:

enter image description here

原始表格中有更多的行和列,但它只是选定的几个产品组,我想将它们平分。

知道如何在Spotfire中做到这一点吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

这可以通过编写TERR数据功能(编辑>数据功能属性>注册新功能)来实现,但这将要求您了解R语言。您将需要将初始数据表传递到函数中,在各行之间循环并使用已有的逻辑写入新行。这将为您提供一个新的数据表,您可以将其输出回Spotfire。

outputDataTable <- inputDataTable[0,]

for(i in 1:nrow(inputDataTable)) {

  product <- inputDataTable[i,1]
  sales <- inputDataTable[i,2]
  newRow1 <- data.frame(Product=paste(product,1, sep="_"), Sales=sales/2)
  newRow2 <- data.frame(Product=paste(product,2, sep="_"), Sales=sales/2)
  outputDataTable <- rbind(outputDataTable, newRow1, newRow2)
}
相关问题