怎么split1列成3列

“2,4-滴异辛酯/2,4-D-ethylhexyl:7%;莠去津/atrazine:28%;乙草胺/acetochlor:42%”这字符串中三种有效成分,每种有效成分间用';'分隔。

t=table(["2,4-滴异辛酯/2,4-D-ethylhexyl:7%;莠去津/atrazine:28%;乙草胺/acetochlor:42%", "2,4-滴异辛酯1/2,4-D-ethylhexyl:7%;莠去津1/atrazine:28%;乙草胺1/acetochlor:42%"] as ContentInfo,1..2 as id )

select split(ContentInfo, ";") as `c1`c2`c3 from t

执行select语句报:

The first argument for 'split' must be scalar string。

然后我用each函数如下:

select each(split,ContentInfo, ";") as `c1`c2`c3 from t 

执行报错:

Not allowed to create a matrix with type STRING
阅读 1.4k
1 个回答

def splitContent(msg){
    size=msg.size()
    result1=array(STRING,size,size)
    result2=array(STRING,size,size)
    result3=array(STRING,size,size)
    for(i in 0:size){
        m=split(msg[i],";")
        result1[i]=m[0]
        result2[i]=m[1]
        result3[i]=m[2]

    }
    return [result1,result2,result3]
}

select splitContent(ContentInfo) as `c1`c2`c3 from t
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进