Omar André Gonzáles Díaz
2015-Sep-29 15:24 UTC
[R] Regex: just keep the money and not the description
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"
Omar André Gonzáles Díaz
2015-Sep-29 15:30 UTC
[R] Fwd: Regex: just keep the money and not the description
Excuse me, here is the vector: TV_Precios2 <- c("S/. 2,499.00S/. 1,999.00", "S/. 2,299.00 S/. 1,599.00", "S/. 2,299.00 S/. 1,599.00", "S 40\" FULL HD 40LF6350S/. 1,999.00S/. 1,699.00", "S/. 5,999.00S/. 4,799.00", "S/. 3,499.00S/. 2,999.00", "S/. 4,799.00S/. 3,699.00", "S/. 599.00", "S/. 1,299.00", "S/. 999.00 S/. 799.00", "S/. 1,999.00 S/. 1,699.00", "S/. 999.00 S/. 849.00", "S/. 499.00 S/. 439.00", "S610S/. 1,899.00", "S/. 1,799.00S/. 1,699.00", "S/. 2,299.00S/. 1,699.00", "S/. 8,999.00S/. 7,299.00", "S9000S/. 10,999.00S/. 8,999.00", "S9000S/. 14,999.00S/. 12,999.00", "S/. 6,999.00S/. 5,999.00", "S/. 2,799.00S/. 2,299.00", "S/. 2,999.00S/. 2,649.00", "SMART 49LF5900S/. 2,399.00S/. 2,149.00", "S/. 2,299.00 S/. 1,599.00" ) ---------- Forwarded message ---------- From: Omar Andr? Gonz?les D?az <oma.gonzales at gmail.com> Date: 2015-09-29 10:24 GMT-05:00 Subject: Regex: just keep the money and not the description To: "r-help at R-project.org" <r-help at r-project.org> 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"
Engin Toksoz
2015-Sep-29 17:25 UTC
[R] Fwd: Regex: just keep the money and not the description
gsub(pattern = "(S[^/]{0,}/.)([:space:]{0,})([0-9,]{0,})(\n){0,}",replace="", TV_Precios2) -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Omar Andr? Gonz?les D?az Sent: Tuesday, September 29, 2015 11:31 AM To: r-help at R-project.org Subject: [R] Fwd: Regex: just keep the money and not the description Excuse me, here is the vector: TV_Precios2 <- c("S/. 2,499.00S/. 1,999.00", "S/. 2,299.00 S/. 1,599.00", "S/. 2,299.00 S/. 1,599.00", "S 40\" FULL HD 40LF6350S/. 1,999.00S/. 1,699.00", "S/. 5,999.00S/. 4,799.00", "S/. 3,499.00S/. 2,999.00", "S/. 4,799.00S/. 3,699.00", "S/. 599.00", "S/. 1,299.00", "S/. 999.00 S/. 799.00", "S/. 1,999.00 S/. 1,699.00", "S/. 999.00 S/. 849.00", "S/. 499.00 S/. 439.00", "S610S/. 1,899.00", "S/. 1,799.00S/. 1,699.00", "S/. 2,299.00S/. 1,699.00", "S/. 8,999.00S/. 7,299.00", "S9000S/. 10,999.00S/. 8,999.00", "S9000S/. 14,999.00S/. 12,999.00", "S/. 6,999.00S/. 5,999.00", "S/. 2,799.00S/. 2,299.00", "S/. 2,999.00S/. 2,649.00", "SMART 49LF5900S/. 2,399.00S/. 2,149.00", "S/. 2,299.00 S/. 1,599.00" ) ---------- Forwarded message ---------- From: Omar Andr? Gonz?les D?az <oma.gonzales at gmail.com> Date: 2015-09-29 10:24 GMT-05:00 Subject: Regex: just keep the money and not the description To: "r-help at R-project.org" <r-help at r-project.org> 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" ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Nothing in this message is intended to constitute an electronic signature unless a specific statement to the contrary is included in this message. Confidentiality Note: This message is intended only for the person or entity to which it is addressed. It may contain confidential and/or privileged material. Any review, transmission, dissemination or other use, or taking of any action in reliance upon this message by persons or entities other than the intended recipient is prohibited and may be unlawful. If you received this message in error, please contact the sender and delete it from your computer.