首页 > 解决方案 > 点火情节元素列表

问题描述

我有一个具有这种格式的数据表:

在此处输入图像描述

我想绘制温度到时间,知道怎么做吗?

标签: listdatatabletransformationspotfire

解决方案


这可以在 TERR 数据函数中完成。我不知道您将 Spotfire 与 TERR 集成起来有多舒服,例如这里有一个介绍视频(演示从大约 7 分钟开始):

https://www.youtube.com/watch?v=ZtVltmmKWQs

考虑到这一点,我在没有加载任何库的情况下编写了脚本,因此它非常冗长和明确,但希望更容易一步一步地遵循。我确信有一种更优雅的方法,并且有更好的方法可以使其灵活地使用列名,但这是一个开始。

您的输入将是一个数据表(dt,原始数据),输出一个新数据表(dt.out,转换后的数据)。所有列名(和一些值)都在脚本中显式处理(因此,如果您更改它们,它将不起作用)。

#remove the []
dt$Values=gsub('\\[|\\]','',dt$Values)

#separate into two different data frames, one for time and one for temperature
dt.time=dt[dt$Description=='time',]
dt.temperature=dt[dt$Description=='temperature',]

#split the columns we want to separate into a list of vectors
dt2.time=strsplit(as.character(dt.time$Values),',')
dt2.temperature=strsplit(as.character(dt.temperature$Values),',')

#rearrange times
names(dt2.time)=dt.time$object  
dt2.time=stack(dt2.time) #stack vectors
dt2.time$id=c(1:nrow(dt2.time)) #assign running id for merging later
colnames(dt2.time)[colnames(dt2.time)=='values']='time'

#rearrange temperatures
names(dt2.temperature)=dt.temperature$object  
dt2.temperature=stack(dt2.temperature) #stack vectors
dt2.temperature$id=c(1:nrow(dt2.temperature)) #assign running id for merging later
colnames(dt2.temperature)[colnames(dt2.temperature)=='values']='temperature'  

#merge time and temperature
dt.out=merge(dt2.time,dt2.temperature,by=c('id','ind')) 
colnames(dt.out)[colnames(dt.out)=='ind']='object'
dt.out$time=as.numeric(dt.out$time)
dt.out$temperature=as.numeric(dt.out$temperature)

盖亚


推荐阅读