'Error (argument is of length zero) when using if loop in R for two times

I want write if loop in R 2 times like the below code but I get an error (Error in if (if (isTRUE(shapiro.test(X)$p.value >= 0.05) == TRUE) { : argument is of length zero ) how can I correct it?

if ( if(isTRUE(shapiro.test(X)$p.value>=0.05)==TRUE) {t.test(X, alternative = "two.sided")$p.value>=0.05} ) {
      b <- total/1000}
    else {b <- 1 - total/1000}
r


Solution 1:[1]

I think you mean to do this:

b = ifelse(
  test = all(shapiro.test(X)$p.value>0.05, t.test(X,alternative="two.sided")$p.value),
  yes = total/1000,
  no = 1-total/1000
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 langtang