-4

I wish to do the following:

  if  X>Y and 
      Z>A and
      B>Y then print ("SUCCESS")
else LOAD NEXT VARIABLES AND REPEAT 

What would be the best way to go about this in r?

  • 1
    are `X,Y,Z,A,B` vectors or elements? – user1317221_G Dec 12 '13 at 12:53
  • 1
    Hi, welcome to SO. Since you are new here, you might want to read the [**about**](http://stackoverflow.com/about) section of the website to help you get the most out of it. Please also read [**how to make a great reproducible example**](http://stackoverflow.com/q/5963269/1478381) and update your question accordingly! – Simon O'Hanlon Dec 12 '13 at 13:00
  • 1
    The best way would be LEARN SOME R AND REPEAT until you've learnt **at least** the basics. – Spacedman Dec 12 '13 at 15:04

1 Answers1

3
X = 2
Y = 1
Z = 4
A = 2
B = 2

if( X > Y & Z > A & B > Y){
  print("SUCCESS")
  }else{
  print("do somethng else")
}

# similarly
#if( X > Y && Z > A && B > Y){
#  print("SUCCESS")
#  }else{
#  print("do somethng else")
#}
###################################

To repeat the function it might be easier to do:

repeat{
  X = sample(1:10, 1)
  Y = sample(1:10, 1)
  Z = sample(1:10, 1)
  A = sample(1:10, 1)
  B = sample(1:10, 1)
  if( X > Y & Z > A & B > Y){
    print("success")
    break
  }
 }

working on this sort of logic:

n = 1

repeat{
 print("success")
 n <- n+1
  if( n > 10){
    print("stop now")
    break
  }
 }
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "success"
#[1] "stop now"
user1317221_G
  • 15,087
  • 3
  • 52
  • 78