I have the following data, which consists of "Frequency" information that I extracted using a Python Script. I want to use this information to generate a WordCloud2
in R.
WORD VALUE SENT
1 topnotch 1 1
2 good 2 1
3 nice 11 0
4 inspired 14 0
5 beautiful 21 0
As I have already done the data pre-processing and cleaning in a previous step, I have no need to go through the steps that are being explained to me in all of the tutorials that I am reading, such as:
conv2 <- Corpus(VectorSource(abstracts))
text.corpus = tm_map(conv2, removePunctuation)
text.corpus = tm_map(text.corpus, content_transformer(tolower))
text.corpus = tm_map(text.corpus, removeWords, stopwords("english"))
However, I still need to convert my data into a proper matrix in order to index it correctly to generate a WordCloud
, this indexing process typically consists of the following steps:
tdm <- TermDocumentMatrix(text.corpus)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
I have been looking to find examples of what the format should be so that I can directly encode my frequency table into the tdm/df necessary for WordCloud2
. Can anyone point me in the direction to the code, as directly calling my table into the TDM has not worked thus far, example:
tdm <- TermDocumentMatrix(mr)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
The errors that I am receiving are the following:
Error in UseMethod("TermDocumentMatrix", x) :
no applicable method for 'TermDocumentMatrix' applied to an object of class "data.frame"
> m <- as.matrix(tdm)
Error in as.matrix(tdm) : object 'tdm' not found
> v <- sort(rowSums(m),decreasing=TRUE)
> d <- data.frame(word = names(v),freq=v)
when trying, as suggested below to use as.TermDocumentMatrix
, I get the following error:
> tdm <- as.TermDocumentMatrix(mr)
Error in .TermDocumentMatrix(x, weighting) :
argument "weighting" is missing, with no default