Can we have an if loop inside a for loop in R programming

+1 vote

I'm using R programming and this code is giving error:

for(i in 1:length(abc)){
  print(i)
  if(){}
}

Any help would be appreciated

Dec 21, 2018 in Data Analytics by Tyrion anex
• 8,690 points
143 views

1 answer to this question.

0 votes

You're If loop doesn't have any condition and Empty conditions result in an error:

> if(){}
Error: unexpected ')' in "if()"

Use TRUE or FALSE if you want to run the loop.


answered Dec 21, 2018 by Sophie may
• 10,550 points

Related Questions In Data Analytics

0 votes
2 answers

R function for finding the index of an element in a vector?

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

answered Dec 12, 2020 in Data Analytics by Rajiv
• 8,890 points
46,411 views
0 votes
1 answer

Check if a matrix is diagonalizable in R Programming Language

On a given matrix, a, the first way ...READ MORE

answered Dec 24, 2018 in Data Analytics by Tyrion anex
• 8,690 points
470 views
0 votes
1 answer

How can we trim leading and trailing whitespaces in R?

trimws {base} //Remove Leading/Trailing Whitespace Removes leading and/or ...READ MORE

answered Apr 18, 2018 in Data Analytics by zombie
• 3,790 points
1,361 views
+1 vote
2 answers

How can we count TRUE values in a logical vector?

Hi, You can get a count of all ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,010 points
7,860 views
0 votes
1 answer

How to break for loop in an if statement

You can break out of each loop ...READ MORE

answered Nov 16, 2018 in Python by Jino
• 5,820 points
1,305 views
0 votes
1 answer

R programming: loop difference

Use the lubridate package to do this: d$departure ...READ MORE

answered Jan 17, 2019 in Data Analytics by Sophie may
• 10,550 points
122 views
0 votes
2 answers

R Programming error in if condition

Hi. Instead of breaking the line add it ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 33,010 points
197 views
0 votes
1 answer

For loop in R programming.

Hi@akhtar, You can create a loop in R ...READ MORE

answered Oct 6, 2020 in Data Analytics by MD
• 95,300 points
104 views
0 votes
3 answers

Can a C program be written in R programming language?

If you have a algorithm you can ...READ MORE

answered Apr 9, 2019 in Data Analytics by anonymous
617 views
+1 vote
1 answer

How to create a 2D array of vectors of different lengths in R programming?

You can try making a list of matrices ...READ MORE

answered Feb 1, 2019 in Data Analytics by Sophie may
• 10,550 points
237 views