How can I write this code so that I can see the sum of positive words for each row?

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

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.