0

So I am suppose to Use && and/or || and reprogram the NthRoot function. The NthRoot Function code is this:

NthRoot<-function(m,n) {
    if(!is.integer(n)!=1) {
      stop("Error: N must have length 1. Go away.")
      }
    else if (!is.integer(n) | is.numeric(n)) {
      return(m^1/n)
      }
   else
     stop('Error: You must input an interger or vector of intergers. 
Existing...\n\n')}

When I replace if and else if, with double & and double |, I receive an error message, Error: unexpected '&&' in: "NthRoot<-function(m,n) { &&". I am having a hard time understanding this part of R programming so I'm struggling a lot. Any help is greatly appreciated. Thank you

spethy39
  • 3
  • 1
  • Welcome to Stack Overflow! It would help us help you if you add the code that you used when you receive the error. From what it looks like, you have omitted completely the `if` statement? – duckmayr Mar 27 '19 at 23:53
  • 2
    Use `if (is.integer(n))`, no need for `!=1`, certainly no need for `!is.integer(n)!=1`, that's a whole lot of double-negation. Whatever is in that `if` clause should return a logical, and `is.integer` by definition does so. However, your error message suggests you really mean `if (length(n) != 1)`, so there's a bit more confusion. – r2evans Mar 28 '19 at 00:08
  • Possible duplicate of https://stackoverflow.com/q/7953833/3358272 – r2evans Mar 28 '19 at 00:10

0 Answers0