Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to find bag of words in R?

Description

To find bag of words in R

Libraries Required :

library(qdap)

Functions used :

bag_of_words(x,apostrophe.remove) – To find the bag of words (x – text ,apostrophe.remove – To remove apostrophe)

Process

  Load required libraries

  Load the data

  Use the function bag_of_words() to find the bag of words

Sapmle Code

#Load necessary libaries
library(“readtext”)
library(qdap)
data data1=(strsplit(data$text,”\n”))
data2=unlist(data1[[1]])
data3=strsplit(data2,”\t”)
data4=unlist(data3)
i=0
j=0
k=0
text=c()
pol=c()
for (i in (1:length(data4)))
{
if(i%%2!=0)
{
j=j+1
text[j]=data4[i]
}else
{
k=k+1
pol[k]=data4[i]
}
}
df=data.frame(text=text,polarity=pol,stringsAsFactors = FALSE)
df$text[1:10]
#To find the bag of words
bag_o_words(df$text[1:10])
bag_o_words(df$text[1:10], apostrophe.remove = TRUE)

Screenshots
find bag of words in R
Load required libraries
Load the data