I want to extract the highest numeric value from each string considering that sometimes that string will be an NA, which will be copied as NA.
I've tried the following solution:
df2$val = sapply(strsplit(df2$NomNivelComplej , '\\D+'), function(x) max(as.numeric(x)))
But all I get is NA
Data
df2 = structure(list(IdCx = c(47111L, 47111L, 47111L, 47111L, 47108L,
47108L, 47107L, 47107L, 47106L, 47106L), NomNivelComplej = c("De 111 Hasta 130 U.V.R.",
NA, "De 111 Hasta 130 U.V.R.", "De 111 Hasta 130 U.V.R.", "De 91 Hasta 100 U.V.R.",
"De 131 Hasta 150 U.V.R.", "De 31 Hasta 40 U.V.R.", "De 71 Hasta 80 U.V.R.",
"De 111 Hasta 130 U.V.R.", "De 111 Hasta 130 U.V.R.")), row.names = c(NA,
10L), class = "data.frame")