Split one column into two

Hello colleagues,
How can I split the column "campaign" by character "|" into 2 colums: campaign name and campaign id?
For example, i need "vertical_cis-kzh_v_net_v_g-cert-classic" and "15383364954" seperately from "vertical_cis-kzh_v_net_v_g-cert-classic|15383364954".

This function would be good for the job:
Separate a character column into multiple columns with a regular expression or numeric locations — separate • tidyr (tidyverse.org)

1 Like

@nirgrahamuk Thanks, it works properly when i try to separate "google / cpc" for example
There are incorrect separation in my situation:
separate(IVI_my_ga,"campaign",into = c("campaign","campaign_id"), sep = "|")
I`ve got a warning: bad offset into UTF string
Maybe the problem is "vertical_cis-kzh_v_net_v_g-cert-classic|15383364954"
"vertical_cis-kzh_v_net_v_g-cert-classic" - words
"15383364954" - numbers

seems to be this issue
separate() fails with Arabic text · Issue #1085 · tidyverse/tidyr (github.com)

but perhaps you can throw away non ascii characters and by pass this issue ?
transform campaign with stringi::stri_enc_toascii() perhaps

I'll think about it a bit later

separate("campaign",into = c("campaign","campaign_id", "xxxxxx"), remove = F, sep = "\ |")

R understands "|" as "or", so he seperates meanings incorrectly. The problem is solved by using that \ |

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.