regex - Extract all numeric values in Columns in R -
i working large data set using r. so, have column called "offers". column contains text describing 'promotions' companies offer on products. trying extract numeric values these. while, cases, able using combination of regex , functions in r packages, unable deal couple of specific cases of text shown below. appreciate on these.
"buying ensures savings of $50. online credit worth 35$ available. buy soon!"
1a. want both numeric values out in 2 different columns. how go that?
1b. problem have solve, need take value associated credit. case texts above, second numeric value in text, if exists, 1 associated credit.
"get 50% off on 3 night stay along 25 credits, offer available on 3 december 2016"
(how should take value associated credits?)
note: efficiency important because dealing 14 million rows.
i have tried looking online solution have not found satisfactory.
i not 100% sure want may you.
a <- "do 50% , whatever 23" b <- gregexpr("\\d+",a)[[1]] firstnum <- substr(a,b[1],b[1]+attr(b,"match.length")[1]-1) secondnum <- substr(a,b[2],b[2]+attr(b,"match.length")[2]-1)
hope helps.
Comments
Post a Comment