I have a a dataframe, which has three possible values, "Up", "Down" or NA.

dim(df) = 61,5

I want to replace all "Up" values by +2

All "Down" values by -2

All NA values by 0

I have created the following function but I keep on getting this error:

```
Binaryexpress <- function(x){
  for(i in 1:5){
  j<-1
while(j<= 61){
  if (x[j,i] == "Down"){
    x[j,i] <- -2
    j <- j+1

  } else if(x[j,i] == "Up"){
    x[j,i] <- 2
    j<- j+1

  }else if(is.na(x[j,i]) == TRUE){
    x[j,i] <- 0
    j<- j+1

  }
  i<- i+1
}
}
}

 Error in if (x[j, i] == "Down") { : missing value where TRUE/FALSE needed

```

I have tried other methods also on the forum, such as -> df[df == NA] <- 0 , but this has not worked either.

EDIT::

Dataframe looks like this:

```
 x1    x2    x3    x4    x5
y Up  Down   NA    NA    Up
k Down NA    Up    NA    NA
l .     .    .     .     .
m .     .    .     .     .
.
.

```

Thank you all in advance,