[R] GSUB function and regex problem

Omar André Gonzáles Díaz oma.gonzales at gmail.com
Mon Aug 18 11:13:28 CEST 2014


Hi all, i have this data.frame with 3 columns: "campaña", "visitas",
"compras".

This is the actual data.frame:

 Campaña                  Visitas       Compras
1 facebook-Ads1       524                   2
2 faceBOOK-Ads1     487                   24
3 fcebook-ads12        258                  4
4        Email1              8                      7
5         mail1               224                  2
6     referral1              147                  7

And i want to replace all the entries on the "campaña" :

from this: "facebook-Ads1" or this: "faceBOOK-Ads1"--> to this: "FBAds".

These are my steps:

1) I load the CSV file into R:

DataGoogle1 <- read.csv(file = "DataGoogle2.csv", header = T)

2) and then use:

gsub("facebook-Ads1", "FBAds", DataGoogle1)

But the result is not what i'm expecting:

i get:

> gsub(pattern = "facebook-Ads1", "FBAds", DataGoogle1)
[1] "c(2, 3, 4, 1, 5, 6, 7, 8, 9)"                "c(524, 487, 258, 8, 224,
147, 87, 863, 145)"
[3] "c(2, 24, 4, 7, 2, 7, 5, 23, 14)"

May you help me to understand why it is not working? Thanks! :D

	[[alternative HTML version deleted]]



More information about the R-help mailing list