I'm trying to get the numbers (including decimals) from a string. My data is similar to this:
V <- c("7.20-<7.35","25-<32","60-<83e","40-<50","0.85-<1.15","80-<98","3.0-<3.4","NA","3.0-<3.4 (110)")
Where numbers are mixed with letters and symbols. I need to extract the first number after the < symbol while keeping the index for the missing values. My output would look like:
desired.output <- c(7.35, 32, 83, 50, 1.15, 98, 3.4, NA, 3.4)
I have tried:
resp <- as.numeric(unlist(regmatches(V,
gregexpr("[[:digit:]]+\\.*[[:digit:]]*",V))))
and
resp <- sub(".*<(^[^-])", "\\1", V)
and another patterns in the sub function but nothing seems to work.
What do you suggest as best approach?