Check if the conditions I made are correct

I would like to know if the code below is properly written for generating group_cols. Making a brief explanation of the code I made:

My first if() is if I have any row where PV$DTT == DTest & PV$Week== Wk. The else if is when I have PV$Week == Wk and PV$Category==CategoryChosse, but not PV$DTT == DTest. That's why I inserted the sign !. The last condition means if I don't have any of the conditions reported above. Is the code correct according to my thinking?

PV <- structure(list(date2 = c("2021-06-23", "2021-06-24"), Week = c("Wednesday", 
 "Thursday"), Category = c("ABC", "FDE"), DTT = c("Hol", "Hol"), DR1 = c(4, 1), 
DR01_PV = c(0, 0), DR02_PV = c(0, -1), DR03_PV = c(-5,-4), DR04_PV = c(-1, -3), 
DR05_PV = c(-1, -3)), class = "data.frame", row.names = 1:2)

dmda<-"2021-07-01"
CategoryChosse<-"FDE"
DTest<-"0"
Wk<-"Thursday"

group_cols <-
  if (any(PV$DTT == DTest & PV$Week == Wk, na.rm = TRUE)) {
    c("Category", "Week", "DTT")
  } else if (any(PV$Week == Wk & PV$Category == CategoryChosse & !PV$DTT == DTest, na.rm=TRUE)) {
    c("Category", "Week")
  } else {
    "Week"
  }

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