Convert comma separated string to integer in R

前端 未结 2 1874
长情又很酷
长情又很酷 2020-12-21 12:29

I have a line in following format

IP1: IP2: 0.1,0.5,0.9

I split this line using following command:

myVector <- (strsplit(oneLine, \":\"))

2条回答
  •  半阙折子戏
    2020-12-21 12:50

    You can use gregexpr and regmatchesto extract the numbers:

    as.numeric(unlist(regmatches(oneLine, gregexpr("-?\\d+\\.\\d+", oneLine))))
    # [1] 0.1 0.5 0.9
    

提交回复
热议问题