0

i tried to create a custom function which intends to estimate a na-value as the arithemtic average between two non-na-values and set in to the specific na-field in the data(how useful this estimation is shall not be the question here); But somehow my code does not work and i don't understand why, maybe you can help me; Here is the code:

#x == Vector of NA's (e.g.: x = which(is.na(y)))
#y == vector/matrix of Data

interpolate = function(x, y){
  c = length(x)
  for (i in 1:c){
    d       = x[i]
    e       = 1
    success = !is.na(y[d+e])
    while (success = FALSE){
      e = e+1
    }
    if (success = TRUE) {
      y[d] = (y[d-1] + y[d+e])/2
      e = 1
    }
  }
}

It produces three times the error: Unexpected '}' in " }" (...)

Erin Sprünken
  • 400
  • 2
  • 13
  • If `success` is logical no need to compare use as is, instead of `if(success == FALSE)...` use `if(success)...` or `if(!success)...` – zx8754 Jun 22 '17 at 09:16

1 Answers1

1

R logic equal is ==, not =. That should solve your problem

jf328
  • 6,841
  • 10
  • 58
  • 82