R Programming error in if condition

0 votes

I am new to R programming and when I run the below if condition:

if("TRUE") 
print("YES")

I get an error.

I know the logic, it's quite simple, but why am I unable to run this if loop?

Jan 18, 2019 in Data Analytics by Sophie may
• 9,940 points
103 views

2 answers to this question.

0 votes

There's a small mistake in your syntax. This should work:

if (TRUE){
  print("YES")
}
answered Jan 18, 2019 by Tyrion anex
• 8,380 points
0 votes

Hi.

Instead of breaking the line add it in the same line as it is a single statement condition.

if("TRUE") print("Yes")
answered Aug 26, 2019 by anonymous
• 32,460 points

Related Questions In Data Analytics

+1 vote
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 23 in Data Analytics by Molly
• 130 points
88 views
0 votes
1 answer

"Error in if" while trying to execute simple code in R

This caused non-logical data or missing values passed ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 51,890 points
76 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
• 51,890 points
389 views
0 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 51,890 points
5,674 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
• 9,940 points
72 views
0 votes
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
• 32,460 points
348 views
+9 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,680 points
170 views
0 votes
1 answer

How can I perform word stemming in R

The tm package in R provides the stemDocument() function to stem the ...READ MORE

answered Aug 20, 2018 in Data Analytics by Abhi
• 3,680 points
223 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,380 points
115 views
0 votes
1 answer

R programming error

Alright, you can either use gsub to match the ...READ MORE

answered Dec 18, 2018 in Data Analytics by Tyrion anex
• 8,380 points
64 views