-4

I have a column in my data frame having values like

enter image description here

I want the resultant Dataframe of the format:

enter image description here

www
  • 38,575
  • 12
  • 48
  • 84
Rameez Shaik
  • 31
  • 1
  • 5

1 Answers1

2
DF$Col5 <- gsub('/.*?/','', DF$Col1)
Balter
  • 1,085
  • 6
  • 12
  • 1
    Had an extra dot. – acylam Aug 28 '17 at 16:46
  • 1
    Seems bizarrely dependent on the length of the path. Tbh, I have no idea how it's meant to work but it fails with...`gsub('/.*?/','', c("/A/B/C/abc", "/abc"))`. Probably, you just want the `basename` function. – Frank Aug 28 '17 at 16:49
  • 1
    Thanks for the heads up on the dot. Frank, I assumed these were not file paths and were a list of companies or something in the strict format listed. – Balter Aug 28 '17 at 16:54
  • 1
    @Frank The multiple slashes in your example would require a different pattern. Balter's solution matches the first forward slash, then more than one of any character, until another forward slash is matched. – Mako212 Aug 28 '17 at 16:55
  • @Mako212 Ok, thanks, I get it now. – Frank Aug 28 '17 at 16:56
  • @Frank Check my updated answer for matching your example – acylam Aug 28 '17 at 17:25
  • Yeah, that's better / more general (assuming I'm right about what the OP is after). Thanks – Frank Aug 28 '17 at 18:28