[R] Regex: just keep the money and not the description

Omar André Gonzáles Díaz oma.gonzales at gmail.com
Tue Sep 29 17:24:52 CEST 2015


Hi R users, I have a character vector with 2 numbers: old price, new
price. The problem is that some rows (4,23, for example) contain a
little description of the product, which I don't need.

I've tried a lot of thins, like this one:

TV_Precios3 <- gsub("^S ^[0-9]{2}\\$","",TV_Precios2)

Without result. Any help is welcome.

After that I want to separate them with colsplit (have this solved)
based on "S/.".



head(TV_Precios3,50)
 [1] "S/. 2,499.00S/. 1,999.00"
 [2] "S/. 2,299.00  S/. 1,599.00"
 [3] "S/. 2,299.00  S/. 1,599.00"
 [4] "S 40\" FULL HD 40LF6350S/. 1,999.00S/. 1,699.00"
 [5] "S/. 5,999.00S/. 4,799.00"
 [6] "S/. 3,499.00S/. 2,999.00"
 [7] "S/. 4,799.00S/. 3,699.00"
 [8] "S/. 599.00"
 [9] "S/. 1,299.00"
[10] "S/. 999.00  S/. 799.00"
[11] "S/. 1,999.00  S/. 1,699.00"
[12] "S/. 999.00  S/. 849.00"
[13] "S/. 499.00  S/. 439.00"
[14] "S610S/. 1,899.00"
[15] "S/. 1,799.00S/. 1,699.00"
[16] "S/. 2,299.00S/. 1,699.00"
[17] "S/. 8,999.00S/. 7,299.00"
[18] "S9000S/. 10,999.00S/. 8,999.00"
[19] "S9000S/. 14,999.00S/. 12,999.00"
[20] "S/. 6,999.00S/. 5,999.00"
[21] "S/. 2,799.00S/. 2,299.00"
[22] "S/. 2,999.00S/. 2,649.00"
[23] "SMART 49LF5900S/. 2,399.00S/. 2,149.00"
[24] "S/. 2,299.00  S/. 1,599.00"



More information about the R-help mailing list