RT。。。老實說這一章我是抖的。。。可是,加油~blog
# 從1:100中均勻抽取size個數據,replace=TRUE指有放回抽樣,數據能夠重複 x = sample(1:100, size = 100, replace = TRUE) y = x # 隨機設置y中有20%的缺失值 y[sample(x = 1:100, size = 20, replace = FALSE)] = NA # 不設置na.rm=TRUE的話,mean會返回NA,哪怕只有一個缺失值 # mean, weighted.mean, var, sd, min, max, median mean(y, na.rm = TRUE) # weighted.mean weighted.mean(x = y, w = y, na.rm = TRUE) # min, 1st quantile, median, mean, 3rd quantile, max, #NA summary(y) # probs設置想要的分位數,要設置na.rm quantile(y, probs = c(0.25, 0.5, 0.75), na.rm = TRUE)