R use variable within regex

前端 未结 3 1311
孤城傲影
孤城傲影 2021-01-16 02:27

Okay - maybe this is a better example. I am looking for guidance/references on how to reference a variable within a regex - not how to build a regex for this data.

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-16 03:12

    Try this:

    > d1 <- c("CCA: 135 cm/sec ICA: 50 cm/sec", "CCA: 150 cm/sec ICA: 75 cm/sec")
    > t(strapplyc(d1, "\\w+: \\S+ \\S+", simplify = TRUE))
         [,1]              [,2]            
    [1,] "CCA: 135 cm/sec" "ICA: 50 cm/sec"
    [2,] "CCA: 150 cm/sec" "ICA: 75 cm/sec"
    

提交回复
热议问题