Search code examples
rnumberselementstring-lengthremoving-whitespace

Removing character from specific length


I have a column as bellow:

a)1902-2019: -1.05 mm/yr
b)1902-1961: -0.79 mm/yr
c)1962-2019: -1.43 mm/yr

I want to remove character to be as flow:

a)1902-2019
b)1902-1961
c)1962-2019

Would you mind to help me? Thanks in advance


Solution

  • Another option:

    x <- '1962-2019: -1.43 mm/yr'
    gsub(':.*', "", x)