InterruptedException InterruptedException - 1 year ago 89
R Question

Converting a Term Document Matrix to a Term Document Matrix supported by tm library

I have a csv file, where I have all of my documents stemmed in a Term Document Matrix form and a categorical variable as a sentiment.
I'd like to use

tm
's capabilities (terms frequencies etc.). Is there a way to do so, given the data I started with?

# given:

dtm = read.csv(file_path, na.strings="")
dtm$rating = as.factor(dtm$rating)

str(dtm)
# 'data.frame': 2000 obs. of 2002 variables:
# $ ID : int 1 2 3 4 5 6 7 8 9 10 ...
# $ abl : int 0 0 0 0 0 0 0 0 0 0 ...
# ...

head(dtm)
#ID abl absolut absorb accept
#1 1 0 0 0
#2 2 0 0 1

# I'd like to achieve...
tdm <- TermDocumentMatrix(dtm,
control = list(removePunctuation = TRUE,
stopwords = TRUE))

Answer Source

Can you use as.TermDocumentMatrix(df, weighting = weightTf) (in the R package tm) to do what you seek?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download