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
Post a Comment