function - R Extract and get the corresponding Numeric values of a string -


need looking function extract , values of requested string separated "-"

data:

x <- c("aa-aa/bb-11/cc-22/dd-1", "aa-aa/bb-33/cc-331") 

desired output:

bb should vector of (11, 33)  cc should vector of (22, 331) 

you can use stringr task:

library(stringr) x <- c("aa-aa/bb-11/cc-22/dd-1", "aa-aa/bb-33/cc-331") bb <- as.numeric(str_match(x, "/bb-([0-9]+)")[, 2]) cc <- as.numeric(str_match(x, "/cc-([0-9]+)")[, 2]) 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -