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
  • 25,773
  • 19
  • 74
  • 108
Prometheus
  • 994
  • 12
  • 20

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,575
  • 4
  • 51
  • 82
onyambu
  • 49,350
  • 3
  • 19
  • 45
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 = "/"))