0

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?

pch919
  • 19
  • 3
  • can you share a sample of your data and the expected output.. nice that you shared your code(what you tried) but for our better understanding we need a sample data – joel.wilson Jan 25 '17 at 04:35
  • I'm sorry but stackoverflow doesn´t let me upload a picture in this answer to you. I uploaded moments ago with an answer to this post but I think it has been deleted. What wolud you like to know about my data.frame? – pch919 Jan 26 '17 at 02:34
  • assume your data is called `df`. So execute `dput(df)` in your console and share those results here. Also add the expected output that you desire form the df . – joel.wilson Jan 26 '17 at 03:07
  • 1
    Hi everybody: Finnaly, I could solution my problem. Here is the answer. http://stackoverflow.com/questions/3969852/update-data-frame-via-function-doesnt-work – pch919 Feb 09 '17 at 00:09

0 Answers0