If else statements

Suppose that num is a single numeric value. Provide code that will add 1 to num if it is less than 0; subtract 1 from num if it is greater than 0; and leaves num unchanged if it is exactly 0.

please look at the below example :

dff <- data.frame(x=-5:7)
dff %>% mutate(var1=ifelse(x<0,x+1,ifelse(x>0,x-1,x)))
image

var1 is the new defined variable which you want ..

hope this clear .

Kind Regards

Please have a look at our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.