I'm executing the following block of code:

```m <- matrix(c(1:5,NA,7,7,NA),
nrow=3,ncol=3,byrow=T)
print(m)
for ( i in 1:dim(m)[[1]] ) {
mm <- sort(m[i,],na.last=c(NA,NA,T)[[i]])
for ( j in 1:(length(mm)-1) ) {
if ( mm[[j]]==mm[[j+1]] ) {
cat(i,j,mm[[j]],fill=T)
}
}
}```

On running this code i get an error:

``` "Error in if (mm[[j]] == mm[[j + 1]]) { : missing value where TRUE/FALSE needed "
```
Jan 24, 2019 1,033 views

## 1 answer to this question.

You can achieve this by wrapping isTRUE() around your if-condition:

```for ( i in 1:dim(m)[[1]] ) {
mm <- sort(m[i,],na.last=c(NA,NA,T)[[i]])
for ( j in 1:(length(mm)-1) ) {
if ( isTRUE(mm[[j]]==mm[[j+1]]) ) {
cat(i,j,mm[[j]],fill=T)
}
}
}```

Output:

`3 1 7`
• 10,610 points

## R programming error: { : missing value where TRUE/FALSE needed "

This should work: for ( i in 1:dim(m)[[1]] ...READ MORE

## R programming Error: Error in if (d >= 0) { : missing value where TRUE/FALSE needed

Here is my code: for(i in 1:(nrow(moon_sub))){   l_df[i,] <- ...READ MORE

## Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

## Error saying "Error in rnorm() : argument "n" is missing, with no default" in R

Hey @ali, rnorm() function requires an argument, ...READ MORE

+1 vote

## How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

## How to remove certain character from a vector

We can use sub to remove the * by specifying fixed = ...READ MORE

## What are special values in R

Like most programming languages, R has a ...READ MORE

## What does the inf special character mean in R?

inf stands for infinity and only applies ...READ MORE