Text mining- how to build a term-document matrix

0 votes
What I am trying to do is to load a csv file, and convert to an term-document matrix.

Here's a section of my code:

"alert-sample-data-4-mining.csv," "head=TRUE," "myCorpus"

MyCorpus, control=list(wordLengths=c(1,Inf)), and termDocumentMatrix

but receive a notice that read: Error in UseMethod("TermDocumentMatrix", x) : no applicable method for 'TermDocumentMatrix' applied to an object of class "data.frame"
Jun 23, 2022 in Data Analytics by avinash
• 1,840 points
722 views

1 answer to this question.

0 votes

You're not loading the TM library, and you're not building a corpus, to name a couple of things. If your text data is in the csv file's "text" field, try something like this:

read.csv in library(tm) myCorpus ("alert-sample-data-4-mining.csv")
VectorSource(myCorpus$text) - Corpus
TermDocumentMatrix(corpus)

Transform data into actionable insights with our Data Analyst Certification – Enroll today!

answered Jun 24, 2022 by Sohail
• 3,040 points

Related Questions In Data Analytics

0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,925 views
0 votes
1 answer

How to build a correlation matrix in R?

@payal, You want to find the correlation ...READ MORE

answered Oct 28, 2019 in Data Analytics by Cherukuri
• 33,030 points
684 views
0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24, 2019 in Data Analytics by anonymous
19,021 views
0 votes
1 answer

How to import text file as a single character string?

First way: rd<-readChar("temp.txt",file.info("temp.txt")$size) ...READ MORE

answered Apr 23, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,290 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,035 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
1,185 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,892 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,116 views
0 votes
1 answer

How to rename a single column in a data.frame?

data.rename(columns={'gdp':'log(gdp)'}, inplace=True) The rename show that it accepts a dict ...READ MORE

answered Jun 24, 2022 in Data Analytics by Sohail
• 3,040 points
410 views
0 votes
1 answer

How to use the strsplit function with a period

Since the dot has a specific meaning ...READ MORE

answered Jun 24, 2022 in Data Analytics by Sohail
• 3,040 points
802 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP