【发布时间】:2020-08-17 15:18:58
【问题描述】:
我正在学习一些基本的 R 编程,做这个简单的练习给我提出了以下问题,我运行以下代码,但我无法理解返回 NULL 值的原因。
temp <- list(c(3,7,9,6,-1),
c(6,9,12,13,5),
c(4,8,3,-1,-3),
c(1,4,7,2,-2),
c(5,7,9,4,2),
c(-3,5,8,9,4),
c(3,6,9,4,1))
print_info <- function(x) {
cat("The average temperature is", mean(x), "\n")
}
sapply(temp, print_info)
The average temperature is 4.8
The average temperature is 9
The average temperature is 2.2
The average temperature is 2.4
The average temperature is 5.4
The average temperature is 4.6
The average temperature is 4.6
NULL
NULL
NULL
NULL
NULL
NULL
NULL
你能帮助理解为什么我得到这个 NULL 值吗?
谢谢你:)
【问题讨论】: