Replacing the specific values in columns of data frame using gsub in R

后端 未结 2 1856
悲&欢浪女
悲&欢浪女 2021-01-12 23:44

I have data.frame as follows

> df
ID      Value
A_001   DEL-1:7:35-8_1 
A_002   INS-4l:5_74:d
B_023   0 
C_891   2
D_787   8
E_865   DEL-3:65:1s:b
         


        
2条回答
  •  清酒与你
    2021-01-13 00:31

    First letter is not digital:

    df$value <- gsub("^\\D.*", "", df$value)
    

    Or there is '-' in delete value:

    df$value <- gsub(".*-.*", "", df$value)
    

提交回复
热议问题