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)[] ) {
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 79 views

## 1 answer to this question.

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

```for ( i in 1:dim(m)[] ) {
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` answered Jan 24 by
• 9,850 points

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

This should work: for ( i in 1:dim(m)[] ...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

## "no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

## 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