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, 2019 in Data Analytics by Sophie may
• 10,610 points
21,686 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, 2019 by Zulaikha
• 910 points
THANK YOU SO MUCH, MAY GOD BLESS YOU IF YOU BELIEVE IN HIM, IF NOT, THEN I WISH YOU LUCK IN YOUR LIFE, YOU SAVED ME AND MY FELLOW STUDENTS
Hello, @Nouha,

Glad that the above answer did help you with your query and hope to help further. If you feel the above answer worth helpful then do upvote it.

Happy Learning

Related Questions In Data Analytics

+4 votes
0 answers

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

Jun 24, 2020 in Data Analytics by Molly
• 160 points
778 views
+1 vote
0 answers
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, 2019 in Data Analytics by Sophie may
• 10,610 points
887 views
+3 votes
2 answers

Error: could not find function - R Programming

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

answered Aug 23, 2019 in Data Analytics by anonymous
• 33,030 points
32,856 views
+1 vote
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,416 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,840 points
456 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,840 points
2,648 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,840 points
2,416 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, ...READ MORE

answered May 28, 2019 in Data Analytics by Zulaikha
• 910 points
619 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, 2019 in Data Analytics by Zulaikha
• 910 points
696 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP