data:
[1] "the rooms were clean very comfortable and the staff was amazing they went over and beyond to help make our stay enjoyable i highly recommend this hotel for anyone visiting downtown "
[2] "excellent property and very convenient to activities front desk staff is extremely efficient, pleasant and helpful property is clean and has a fantastic old time charm "
[3] "the rooftop cafeteria of hotel was great. wen i say food was great "
code:
x=reviews$Reviews[1:3]
library(tidytext)
library(tm)
bing <- get_sentiments("bing")
positive = bing %>% filter(sentiment %in% "positive")
positive = subset(positive, select = -c(sentiment))
positive = as.vector(positive$word)
positive = paste0(positive," ")
#word count function
positive_reviews <- function(x) {
data = as.vector(x)
data = Corpus(VectorSource(data))
data = tm_map(data, removePunctuation)
data = as.character(data)
data = data[-2]
data = data[-2]
for (i in 1:3) {
positive_count = sapply(positive, function(x) str_count(data,x))
#return(sum(positive_count))
positive_count = rowSums(positive_count)
return(rowSums(positive_count))
row_count=c()
row_count=cbind(positive_count,positive_reviews(x))
}
}
colnames(row_count) <- reviews$Reviews