Extract a string between patterns/delimiters in R

前端 未结 4 1995
借酒劲吻你
借酒劲吻你 2020-12-11 22:24

I have variable names in the form:

PP_Sample_12.GT

or

PP_Sample-17.GT

I\'m trying to use string split to

4条回答
  •  囚心锁ツ
    2020-12-11 22:54

    If they all start and end with the same characters and those characters aren't anywhere in the middle part of your string, the gsub expression is simple:

    > x <- c("PP_Sample-12.GT","PP_Sample-17.GT")
    > gsub('[(PP_)|(.GT)]','',x)
    [1] "Sample-12" "Sample-17
    

提交回复
热议问题