0

For example one of the row contains 9343435445/9433445532. I would like to split these and paste individual ones separately in a new column. I tried the following.

bookings <- read.csv(file = 'bookings.csv', header = T)
bookings$set1 <- as.character(bookings$set1)
bookings$set3 <- gsub('\\/..........', '',bookings$set1)
bookings$set4 <- gsub('\\d{10}\\/', ' ',bookings$set1)

But is not giving the desired output.

pogibas
  • 27,303
  • 19
  • 84
  • 117
Prometheus
  • 1,148
  • 14
  • 21

2 Answers2

5

You can use strcapture from base r (R ≥ 3.4.0)

strcapture("(\\d+)/(\\d+)","9343435445/9433445532",data.frame(A=numeric(),B=numeric()))
           A          B
1 9343435445 9433445532
Cath
  • 23,906
  • 5
  • 52
  • 86
Onyambu
  • 67,392
  • 3
  • 24
  • 53
0

Have a look at http://tidyr.tidyverse.org/reference/separate.html

So something like this: separate(data = data, col = phonenumber, into = c("phonenumber1", "phonenumber2", sep = "/"))