有人可以帮我理解 "function (x)" 中的代码,还有 $out 的作用是什么?

can someone please help me understand the code from the "function (x)" , also what is the role of $out?

我正在学习lapply,谁能帮我理解“function (x)”的代码,以及“$out”的作用是什么?谢谢

outs=lapply(names(qdata[,12:35]), function(x)
        hist(qdata[[x]], data=qdata, main="Histogram of Quality Trait",
             xlab=as.character(x), las=1.5)$out)

这只是生成了一系列直方图。如果我们将 qdata 替换为 mtcars 并进行一些小调整,我们将得到:

par(mfrow = c(3, 4))

lapply(names(mtcars),
       function(x) hist(mtcars[[x]],
                        main = "Histogram of Quality Trait",
                        xlab = as.character(x), las = 1.5))

lapply 在这里所做的是遍历列名并为每一列生成直方图。

您分享的代码中有一些奇怪之处。 $out 不是 hist 生成的对象的成员,因此除了绘制直方图之外,代码 returns 也是 NULL 值的列表。 $out 大概只是一种防止列表将 hist 对象的内容页面吐出到控制台的方法。 outs 变量在此调用后无用。

此外,data 不是 hist 中的命名参数,因此原始代码会为我生成警告。

另一种可能性是这是自定义 hist 函数而不是基本 R 版本。