0

Need help to split the columns as per the different delimiters I am facing issue while using multiple delimiters Below is sample data and expected output.

Sample Data

ContractCd <- c(9940099251,9940080497,9940099251,9940014221)

WBSElementNbr <- c("N1075001,N1075013,MT842001,N1128001,NN480001,N1142001,N1147001","IV768001&IU775001","NN480001;N1147001","D6268001/D6268005")

Sample Data
Data <- data.frame(ContractCd,WBSElementNbr)

Expected Output

ContractCd <- c(9940099251,
                9940099251,
                9940099251,
                9940099251,
                9940099251,
                9940099251,
                9940099251,
                9940080497,
                9940080497,
                9940099251,
                9940099251,
                9940014221,
                9940014221)

WBSElementNbr <- c("N1075001",
                   "N1075013",
                   "MT842001",
                   "N1128001",
                   "NN480001",
                   "N1142001",
                   "N1147001",
                   "IV768001",
                   "IU775001",
                   "NN480001",
                   "N1147001",
                   "D6268001",
                   "D6268005")

Expected Output
Data1 <- data.frame(ContractCd,WBSElementNbr)
JK1185
  • 109
  • 1
  • 8
  • Does this answer your question? [Split comma-separated strings in a column into separate rows](https://stackoverflow.com/questions/13773770/split-comma-separated-strings-in-a-column-into-separate-rows) – camille Feb 13 '20 at 16:22

1 Answers1

1

We can use separate_rows

library(tidyverse)
Data %>%
   separate_rows(WBSElementNbr)
akrun
  • 874,273
  • 37
  • 540
  • 662