Message-ID: <AE02D6FA-593E-43EE-AC3F-0D39AB62702E@comcast.net>
Date: 2013-06-15T16:31:12Z
From: David Winsemius
Subject: A strange issue with GSub
In-Reply-To: <DUB123-W358BA44FA9BA962B2AB0D486810@phx.gbl>
On Jun 15, 2013, at 7:46 AM, Ali Arslan Kazmi wrote:
> Greetings,
>
> Apologies if this turns out to be a very silly question, but because I am the only person learning/using R at my workplace, I have no choice but to ask folks here.
> I have been using Gsub to change some expressions in my Corpus object. After applying the gsub function, say
> newCorpus<- gsub("game","war",newCorpus, fixed=TRUE)
> an object of class character is returned by the gsub function, as is understandable, like so:
> [1] this is the text of the 1st document....[1000] this is the text of the 1000th document.
> However, all such text is enclosed as such:
> [1] "c(\"this is the text of the 1st document.\", \"\\a\")" ...[1000] "c(\"this is the text of the 1000th document.\", \"\\a\")"
> The worst part is that I tried recreating the problem with another example to post here, but I face no such problem with the example. So, after banging my head against the computer for two days now, I still remain clueless as to why this is happening. I was wondering if somebody had an explanation to why this happens? That will be very helpful.
> The only thing I can think of is that I had initially converted MS word documents into txt files, and then imported them using R's plain text reader. Could this be the issue?
>
> Thanks.
> [[alternative HTML version deleted]]
You are misspelling the gsub function name. You are not describing your process with enough detail to replicate it. You are using packages that you are not naming. I suspect you are using gsub with an item of a class for which it was never intended. Consider this:
> mydf <- data.frame(a=c("this is a test", "another test"), b=c("athird", "a fourth"))
> gsub("test","tester", mydf)
[1] "c(2, 1)" "c(2, 1)"
Please read the Posting Guide. Please make your example reproducible.
--
David Winsemius
Alameda, CA, USA