-1

Having into one row of dataframe data like this:

data.frame(text = c("in this line ???? another line and ???? one more", "more lines ???? another row")

separate into many rows using as separation the ????. Here the expected output

data.frame(text = c("in this line", "another line and", "one more", "more lines", "another row")
Nathalie
  • 1,228
  • 7
  • 20

1 Answers1

2

Here is a base R solution

dfout <- data.frame(text = unlist(strsplit(as.character(df$text),split = " \\?{4} ")))

or a more efficient (Thanks to comments by @Sotos)

dfout <- data.frame(text = unlist(strsplit(as.character(df$text),split = " ???? ", fixed = TRUE)))

such that

> dfout
              text
1     in this line
2 another line and
3         one more
4       more lines
5      another row
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81