Q:

How to extract specific number from a string in R

My data is look like this: x = when,ch_d_mean,< , 29.55
I want to extract 29.55 from x. 
x = 'when,ch_d_mean,< , 29.55'

I want to have the value 29.55

A:

Here is a base R option:
x <- "when,ch_d_mean,< , 29.55"
regmatches(x, gregexpr("\\d+(?:\\.\\d+)?",  x))[[1]]

[1] "29.55"

Note that this approach is robust with regard to capturing any quantity of numbers in the input string. 

A:

We can use parse_number from readr
library(readr)
parse_number(x)
#[1] 29.55

or with str_extract from `stringr
as.numeric(str_extract(x, "[0-9.]+"))
#[1] 29.55

Or with gsub from base R
as.numeric(gsub("[^0-9.]+", "", x))
#[1] 29.55

Or using substring from base R
as.numeric(substring(x, nchar(x)-4))
#[1] 29.55

NOTE: The last approach is based on the position if it is at the end of the string and occupies last 5 position

