My data look like this:
106s(1m46s)
0s
15s
60s(1m)
I want to receive only the seconds:
106
0
15
60
How to solve this problem ?
This will do what you want:
s <- c("106s(1m46s)", "0s", "15s", "60s(1m)")
as.numeric(sub("\\D.*$", "", s))
We can use `
library(stringr)
as.numeric(str_extract(str1, "\\d+"))
#[1] 106 0 15 60
str1 <- c("106s(1m46s)", "0s", "15s", "60s(1m)")