Need HELP in writting Nested if else code

Dear community,

I would like to write below code using Nested If else condition using R programming. As I am using Aggregate function(MAX) to get maximum value from it. Do i need to use rowwise()? Can someone help me to get R code for below code,as I am new to R programming.

if (missing(eosdt)) then do;
if (COMPLSFL = 'Y') then
EOSDT = max( __plndeotdt, __plndfudt, __fuassdt);
else if dcsreas ne "DEATH" and not missing(dcsdt) then
EOSDT = dcsdt;
else if dcsreas = "DEATH" and (not missing(dcsdt) or not missing(__adjudicationdt)) then
EOSDT = max(dcsdt, __adjudicationdt);
EOSDT = max(__lastvisitdt, __aeonsetdt, __adjudicationdt);

Thank you for your help.

this is not R code, it looks like SAS code....

Yes, I wanted to right simillar SAS code into R code. Need help in writting Nested loop.

ok, yes, use rowwise, and c_across.
there are many conditional logic tools, such as if_else and case_match, and case_when

in this example :
check if X0_is missing; if its missing then depending on the letter match calculate a different max, if X0_ was not missing use X0_

(example <- cbind(
  X0_ = c(99, NA, NA),
  XA = letters[1:3],
  data.frame(matrix(1:12, nrow = 3))


example |>
  rowwise() |>
    X0_ = if_else(,
        "b" ~ max(c_across(X1:X2)),
        "c" ~ max(c_across(X3:X4))

Thank you for nice example. I will try to implement this approach in my coding.

This topic was automatically closed 7 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.