Posted on 17th September 2024|573 views
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
Posted on 17th September 2024| views
this may work
f <- function(t) {
ifelse(t < 0, 0, 2+a)
}