0

I have a column whose pattern of data is similar to the one here reported:

strings = c('AIR:MT.S:R-V:Q', 
            'AIR:MT.T:P-V:Q')

I am looking for a function I can apply in a way that with dplyr I can remove all the part before the . Thus, the wanted output would be like this:

S:R-V:Q
T:P-V:Q

How it be that possible to do

12666727b9
  • 1,133
  • 1
  • 8
  • 22
  • You could `mutate` with `sub`. Is this what you want: `mutate(strings = sub("^[^\\.]+\\.", "", strings))`? – Quinten May 03 '23 at 11:20
  • Split and get 2nd item, use regex, or using stringr `word(strings, 2, sep = fixed("."))`. – zx8754 May 03 '23 at 11:22
  • 1
    Another near-duplicate may be this question, if you simply change to period from colon: https://stackoverflow.com/questions/12297859/remove-all-text-before-colon – jpsmith May 03 '23 at 11:24
  • Here are some possibilities: `sub("\\..*", "", strings)` or `read.table(text = strings, comment.char = ".")[[1]]` or `scan(text = strings, what = "", comment.char = ".", quiet = TRUE)` – G. Grothendieck May 03 '23 at 11:26

0 Answers0