我有一个如下数据框:
df
ColA ColB
New|ME 7
New|You 8
ten 9
Aim|High 10
预期输出:
ColA ColB First Second
New|ME 7 New ME
New|You 8 New You
ten 9 ten NA
Aim|High 10 Aim High
如何通过定界符|
使用sqldf解析ColA?
这是我的尝试,但收到错误:
library(sqldf)
df1<- sqldf("SELECT * FROM df CROSS APPLY STRING_SPLIT([ColA], '|') ")
Error in result_create(conn@ptr, statement) : near "(": syntax error
答案 0 :(得分:0)
df <- sqldf("SELECT *, SUBSTR([ColA], 1, INSTR([ColA],'|')-1) First FROM df")
df <- sqldf("SELECT *, SUBSTR([ColA], INSTR([ColA],'|')+1, Length([ColA])) Second FROM df")
df <- sqldf("SELECT ColA, ColB, First, Second FROM df")