-5

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 ?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
kenar
  • 1
  • 1

2 Answers2

3

This will do what you want:

s <- c("106s(1m46s)", "0s", "15s", "60s(1m)")
as.numeric(sub("\\D.*$", "", s))
jogo
  • 12,469
  • 11
  • 37
  • 42
0

We can use `

library(stringr)
as.numeric(str_extract(str1, "\\d+"))
#[1] 106   0  15  60

data

str1 <- c("106s(1m46s)", "0s", "15s", "60s(1m)")
akrun
  • 874,273
  • 37
  • 540
  • 662