S
Satish santu

Posted on 18th April 2024|566 views

0
votes

The Condition Has Length 1 And Only The First Element Will Be Used

How to resolve the error the condition has length > 1 and only the first element will be used?

 I created a program something like this

a<-function(x) {

if (x<0){

a<-0

return(a)

}else{

a<-2+a

return(a)

}

    }

Which is displaying an error called In if (t < 0) {: the condition has length > 1 and only the first element will be used

 

Answers
P
jordan chris

Posted on 18th April 2024

this may work 

f <- function(t) {

  ifelse(t < 0, 0, 2+a)

}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos