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

0 votes

Here's my 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 executing this I get an error: 

"Error in if (mm[[j]] == mm[[j + 1]]) { : missing value where TRUE/FALSE needed "

May 28 in Data Analytics by Sophie may
• 9,530 points
331 views

1 answer to this question.

0 votes

This should work:

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)
    }
  }
}
answered May 28 by Zulaikha
• 840 points

Related Questions In Data Analytics

0 votes
1 answer

R programming: Missing value error

You can achieve this by wrapping isTRUE() around your if-condition: for ...READ MORE

answered Jan 24 in Data Analytics by Sophie may
• 9,530 points
42 views
0 votes
1 answer

Error: could not find function - R Programming

This error usually occurs when a package ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,040 points
774 views
0 votes
1 answer

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

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

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,040 points
174 views
0 votes
1 answer

"no applicable method" Error in r programming

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

answered Oct 31, 2018 in Data Analytics by Kalgi
• 39,150 points
57 views
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
86 views
0 votes
1 answer

How to remove certain character from a vector

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

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,040 points
41 views
0 votes
1 answer

What are special values in R

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

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,040 points
35 views
0 votes
1 answer

What does the inf special character mean in R?

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

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,040 points
82 views
0 votes
1 answer

R programming error: Plot error - “Col=”red“

Fix this line: polygon(c(0,0,1),c(1,2,1), col="red", density=c(30,4 ...READ MORE

answered May 28 in Data Analytics by Zulaikha
• 840 points
21 views
0 votes
1 answer

Changing variable values using R programming

This should work: df$symbol <- as.character(df$symbol) df$symbol[df$symbol == "ABCD.BO"] ...READ MORE

answered May 27 in Data Analytics by Zulaikha
• 840 points
19 views