# Step 1: Create text vector
text <- c("R is easy",
"R is useful",
"Text mining is easy",
"Data is useful")
# Step 2: Install and load packages
[Link]("tm")
[Link]("wordcloud")
library(tm)
library(wordcloud)
# Step 3: Create corpus
corpus <- Corpus(VectorSource(text))
# Step 4: Convert text to lowercase
corpus <- tm_map(corpus, content_transformer(tolower))
# Step 5: Create Document Term Matrix
dtm <- DocumentTermMatrix(corpus)
# Step 6: Convert DTM to matrix
m <- [Link](dtm)
# Step 7: Find word frequency
word_freq <- colSums(m)
# Step 8: Display frequency table
word_freq
# Step 9: Create word cloud
wordcloud(names(word_freq), freq = word_freq, [Link] = 1)
# Step 10: Draw bar chart
barplot(word_freq,
main = "Word Frequency",
xlab = "Words",
ylab = "Frequency")
text <- c("I love this product",
"This service is very bad",
"The quality is excellent",
"I hate the delivery",
"The item is good")
[Link]("syuzhet")
library(syuzhet)
score <- get_sentiment(text)
category <- ifelse(score > 0, "Positive",
ifelse(score < 0, "Negative", "Neutral"))
[Link](Text = text, Score = score, Category = category)