r - convert a string range of values to numeric range -
i have following type of values in 1 column of data.
£48.00 - £52.00 first have remove £ sign, done with
v <- gsub('£'," ",£48.00 - £52.00) v string.
> v [1] " 48.00 - 52.00" how can transform v numeric v 48.00 - 52.00?
we use str_extract extract numeric part along .. output list. can loop through list sapply , median after converting 'numeric'.
library(stringr) sapply(str_extract_all(str1, '[0-9.]+'), function(x) median(as.numeric(x))) data
str1 <- "£48.00 - £52.00"
Comments
Post a Comment