I have a problem to assign a value with my function.
x1 is a data.frame
n_grams<- function(x1) {
a<- x1[which(x1[,3]=="relato"),2]
b<- x1[which(x1[,3]=="tiembla"),2]
c<- x1[which(x1[,3]=="kristina"),2]
if(c== a+2) {
x1[c,5]<- -1
}
}
What i´m doing is looking for a combination of three words in my data frame x1. If the words are one after the other ones, the word "kristina" will have the value -1. The number 2 is the column wich indicates the number of position of the word; number five is the score of the word in my data.frame.
For some reason, this code doesn´t work, but if I apply it withougt a function, it makes the assigment perfectly.
The code runs until x1[c,5]<- -1
. I checked.
I tried ifelse()
and the retun vakue was FALSE.
Finnaly, i need a functiion because a have many combinations of words, so it would be more tidy if a create a function instead of spread elements all over my enviroment.
Can anybody help me?