Brute force approach. Not optimal, as uses too many for loops, but seems to be doing what you need. Hopefully, this should be suitable for your application. You can rearrange things or store results in another variable so that the output is w/o [1] [1] etc.
Code:
sent = data.frame(Sentences=c("abundant bad abnormal activity was due to 2-face people","strange exciting activity was due to 2-face people"), user = c(1,2))
pos = c("abound" , "abounds", "abundant", "exciting")
neg = c("2-face","abnormal", "strange", "bad", "weird")
words <- matrix(ncol = 2,nrow=8)
words = (str_split(unlist(sent$Sentences)," "))
tmp <- data.frame()
tmn <- data.frame()
for (i in 1:nrow(sent)) {
for (j in 1:length(words)) {
for (k in 1:length(pos)){
if (words[[i]][j] == pos[k]) {
print(paste(i,words[[i]][j],1))
tmn <- cbind(i,words[[i]][j],1)
tmp <- rbind(tmp,tmn)
}
}
for (m in 1:length(neg)){
if (words[[i]][j] == neg[m]) {
print(paste(i,words[[i]][j],-1))
tmn <- cbind(i,words[[i]][j],-1)
tmp <- rbind(tmp,tmn)
}
}
}
}
View(tmp)
Result:
i V2 V3
1 1 abundant 1
2 1 bad -1
3 2 strange -1
4 2 exciting 1