I have a dataframe like below:
ColA ColB
djdn- 3
dn-dn 5
ndmc- 8
nd-nd-md 9
Expected Output:
ColA ColB New_Col
djdn- 3 djdn
dn-dn 5 dn-dn
ndmc- 8 ndmc
nd-nd-md 9 nd-nd-md
Using sqldf, I want to remove the "-" at the end of the value if it exists at the end.
This is my attempted code:
library(sqldf)
df_new<- sqldf("select CASE(RIGHT([ColA], 1) = '-', LEFT([ColA], LEN([ColA])-1),
[ColA]) [New_Col] from df")
Error in result_create(conn@ptr, statement) : near "(": syntax error