I want to extract just FIRST TWO DIGITS from some strings. Suppose the data is :
ABC Conference Room Monitor - Z5580J ABC 19 Monitor ABC 24 Monitor f
Another solution:
strings <- c('ABC Conference Room Monitor - Z5580J','ABC 19 Monitor','ABC 24 Monitor for Video-Conferencing','ABC UltraSharp 24 Monitor -QU2482Z') x <- as.numeric(gsub("\\D", "", strings)) as.numeric(substring(as.character(x*100), 1, 2)) [1] 55 19 24 24