避免使用 .
正如我们提到过的,在对象名中使用 . 容易引起混淆。
本练习是课程的一部分
R 防御式编程
练习说明
- 请将下面的对象名和参数名重命名,把句点替换为下划线。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Define a function to prevent pasting the code above
ci <- function(x, plot.it = FALSE) {
# Plot the data
if (isTRUE(plot.it)) hist(x)
m <- mean(x); s <- sd(x); n <- length(x)
c(m - 1.96 * s/sqrt(n), m + 1.96 * s/sqrt(n))
}
# Generate 100 normal random numbers
sample.values <- rnorm(100)
ci(sample.values)