[R] GSUB and Data.frame format lost
Omar André Gonzáles Díaz
oma.gonzales at gmail.com
Tue Aug 19 11:21:19 CEST 2014
Hi all,
please, i'm trying to understand how using "Gsub" for some search and
replace of text, makes my data frame lost it's format.
This is my code:
<code>
DataGoogle1 <- read.csv(file = "DataGoogle2.csv", header = T,
stringsAsFactors = F)
head(DataGoogle1)
</code>
Result 1:
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
Then i apply the GSUB function like this:
<code> DataGoogle2 <- as.data.frame(gsub("facebook-Ads1", "FBAds",
DataGoogle1$Campaña)) </code>
And the result is:
DataGoogle2
gsub..facebook.Ads1....FBAds...DataGoogle1.Campaña.
1 FBAds
2 faceBOOK-Ads1
3 fcebook-ads12
4 Email1
5 mail1
6 referral1
...
The Search and Replace works, but my data.frame does not. Even if i use:
"as.data.frame" before of the "gsub" function. Please, tell me what can i
do... Cheers!
[[alternative HTML version deleted]]
More information about the R-help
mailing list