Message-ID: <CAB1cB5U-pj0peXt9_y+2PNRgOSrQv-3K69tFYEZsekw8Drs=Gw@mail.gmail.com>
Date: 2019-06-14T18:18:39Z
From: Chenguang Du
Subject: 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???
--
Chenguang Du
Ph.D Candidate
Educational Research and Evaluation
School of Education
Virginia Tech
[[alternative HTML version deleted]]