Skip to content
Prev 815 / 885 Next

Need help to understand the code

I am reading the book  R in action, but get confused by the following code

mystats <- function(x, na.omit=FALSE){

if (na.omit)

x <- x[!is.na(x)]

m <- mean(x)

n <- length(x)

s <- sd(x)

skew <- sum((x-m)^3/s^3)/n

kurt <- sum((x-m)^4/s^4)/n - 3

return(c(n=n, mean=m, stdev=s, skew=skew, kurtosis=kurt))

}

my question is  when if control statement is used inside the function, why
the { } after the (na.omit)  is not followed???  why it still works???