我是一个初学者,几周前学习了 R,我正在努力学习这个apply
家庭。无法弄清楚如何使用lapply
,这令人抓狂。是的,我查了?lapply
几本书,包括R 简而言之和R 食谱,但仍然无法弄清楚我做错了什么。
lapply(X = c("ggplot2", "gtable", "grid"), library)
## Error: 'package' must be of length 1
lapply(X = c("ggplot2", "gtable", "grid"), FUN = function(x) library(x))
## Error: there is no package called 'x'
lapply(X = c("ggplot2", "gtable", "grid"), FUN = library)
## Error: 'package' must be of length 1
x = c("ggplot2", "gtable", "grid")
lapply(x, library)
## Error: 'package' must be of length 1
lapply(x, FUN = function(x) library(x))
## Error: there is no package called 'x'