Example DF:
country <- c('Australia', 'Italy', 'Peru', 'China')
score <- c("0.091", "0.413,.", "-", "0.102,0.102,0.102,.,.,.,.,.,.,.,.")
country_scores <- data.frame(country, score)
Each entry of score can have any number of comma separated values or a “-” for no data. I am looking to extract the largest value in the string and test whether it meets a certain threshold. I tried a solution from /a/65121200/8621123 but the solution is very slow (at least 8 minutes) on my data frame of 1.3 million rows and 186 columns:
library(tidyverse)
country_scores %>%
mutate(scores = str_extract_all(score, '\d+(\.\d+)?'),
score_max = map_dbl(new, ~max(as.numeric(.x))))