Remove a suffix to a value of a data frame

后端 未结 2 1126
忘掉有多难
忘掉有多难 2021-01-07 05:07

I have a data frame done this way:

 a       b         c
--------------------------------
 1     2011     mal ID9     
 2     2012     yesterday ID10 
 3              


        
相关标签:
2条回答
  • 2021-01-07 05:44

    This should work

        z$c=gsub(" ID.*","",z$c)
    
    0 讨论(0)
  • 2021-01-07 05:47

    You can try something like this:

    z %>% mutate(c = gsub("\\sID\\d+$", "", c))
    
      a    b         c
    1 1 2011       mal
    2 2 2012 yesterday
    3 3 2010     misch
    4 4 1995       mal
    5 5 2008        se
    6 6 1998   falling
    7 7 2011    friend
    8 8 2011 use to be
    
    0 讨论(0)
提交回复
热议问题