简体   繁体   中英

How to write an inequality in R

Sorry, I am an R newbie and I am having some difficulty

How would I write the following inequality in R:

x > 10 is twice more likely than x < 10

I tried this function and it didn't work:

X = 10 

f = function(X,Y) { 
  if ((2(X) >= 10 & X <= 10) { 
    print("in range") 
  } else {
    print("out of range") 
  } 
}

Your code has a syntax error if that's the problem:

X = 10 
f = function(X,Y) {
  if (2 * X  >= 10 && X <= 10) {  # * instead of (
    print("in range") 
  } else { 
    print("out of range") 
  } 
}

You can try your function as in:

 > f(10,10) [1] "in range" > f(20,10) [1] "out of range"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM