-2

I have a good understanding of how I would do this in another computer language, but am having trouble using the dplyr package in R to accomplish this task. I have a tbl dataset that has a column of data, Dip1, that contains strings with names of banks separated by semicolons. Example:

Number  Dip1  

1       Goldman Sachs; Morgan Stanley
2       UBS; Wells Fargo; Wachovia
3       Bank of America
4   

How can I use dplyr to split the strings of the column by the ";"? This is intuitive in other languages by indexing the column and iterating through the rows and splicing by ";", but I am not sure if iteration is needed in this case using dplyr. Thank you.

Cath
  • 23,906
  • 5
  • 52
  • 86
markiv189
  • 151
  • 1
  • 3
  • 9
  • 3
    What is your expected output? Do you need https://stackoverflow.com/questions/15347282/split-delimited-strings-in-a-column-and-insert-as-new-rows ? – Ronak Shah Dec 10 '18 at 07:57

1 Answers1

1

Here is an answer:

require(tidyr)
tbl2 <- tbl %>% separate(Dip1, 
        sep = "; ", 
        into = c("a", "b", "c")
JayJay81
  • 203
  • 1
  • 8
  • 1
    This answer should have `library(tidyr)` and a space in the `sep` argument – Calum You Dec 10 '18 at 09:16
  • When used in this way, `require(tidyr)` accomplishes the same thing as `library(tidyr)`. The second is more common, but the first is acceptable. Execute `?require` at the prompt to learn more. – Michael Tuchman Aug 08 '22 at 10:59