Conditional Flow in R



Decision making/Conditional control Flow  
As other languages R also support conditional flow for the control which can be controlled using if, ifelse or switch commands

Syntax
If()
ElseIf()
Ifelse()

In the case of numeric vector, zero is taken as FALSE, rest as TRUE

Benefits/Usages
 Dynamic content rendered on separate page
Code cleanliness more manageable,
Master / child page structure can be achieved

Code Snippet
          #If
y<-10
if(y==10)
{
 print("This is true")
}

#If..else

if (y<10)
 {
 print("Less than 10")
} else
{
  print("Greter than or equals to 10")
}

#Nested if else……

z <- 1
if (z < 0) {
   print("-ive number")
} else if (z > 0) {
   print("+ive number")
} else
   print("Zero")
Conditional Flow in R Reviewed by Rupesh on 11:23 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.