function and ifelse

Hello
I want to know how to write this function in one step
R :

if (x>0 and x <1/2), y=8/3*x

if (x>=1/2 and x <1), y=4/3

else y=0

Could you say a little more about what you mean by 'in one step'?

Hello dear colleagues
I want to know how to write the following command in R

if (x>0 & x <1/2), y=8/3*x, if (x>=1/2 & x <1), y=4/3, else y=0

thanks

if (x>0 & x <1/2) { y = 8/3*x} else if (x>=1/2 & x <1) {y=4/3} else {y=0}

Is that what you mean?

how to write the following function in R

if x>0 & x <1/2, f(x)=8/3*x ; if x>=1/2 & x <1, f(x)=4/3 ; else f(x)=0
thanks

Just replace y by f(x) here:

Is that what you mean?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.