I'm analyzing a corpus of emails. Some emails contain URLs. When I apply the removePunctuation
function from the tm library, I get httpwww
, and then I lose the info of a web address. What I would like to do, is to replace the "://"
with " "
across all of the corpus. I tried gsub
, but then I the datatype of the corpus changes and I can't continue to process it with tm package.
Here is an example:
As you can see, gsub
changes the class of the corpus to an array of characters, causing tm_map
to fail.
> corpus
# A corpus with 4257 text documents
> corpus1 <- gsub("http://","http ",corpus)
> class(corpus1)
# [1] "character"
> class(corpus)
# [1] "VCorpus" "Corpus" "list"
> cleanSW <- tm_map(corpus1,removeWords, stopwords("english"))
# Error in UseMethod("tm_map", x) :
# no applicable method for 'tm_map' applied to an object of class "character"
> cleanSW <- tm_map(corpus,removeWords, stopwords("english"))
> cleanSW
# A corpus with 4257 text documents
How can I bypass it? Maybe there's a way to convert it back to corpus from array of characters?