【发布时间】:2021-11-04 13:30:49
【问题描述】:
我曾在 Python 中使用 Pandas 对我收集的数据进行一些操作和回归并回答 SO 问题,并认为学习它的灵感可能有助于我的理解。
我正在使用 learn-R 教程,在 vector 和一些关于 SO 和网络的挖掘之后,我来到了这个:
# So assigning a value to v will create an atomic vector
# of length one with a type
v <- 1
is.vector(v) # TRUE
class(v) # 'numeric'
# But literals are also vectors? These all return TRUE
is.vector(1)
is.vector("string literal")
is.vector(TRUE)
is.vector("c")
# and lists are vectors too
l <- list(1, 2, 3)
is.vector(l) # TRUE
那么R中的一切都是向量吗?
【问题讨论】:
-
R的基本数据结构包括:vectors、lists、data.frame和matrix
-
(@tushaR,我会概括“矩阵”:它只有 2 个维度,而
"array"可以有任意数量的维度,但在其他方面完全兼容。identical(matrix(1:3, nrow=1), array(1:3, dim=c(1,3)))是真的。) -
R 没有标量数据类型。所有数据类型都是原子或通用向量(列表)。我建议阅读语言定义:cran.r-project.org/doc/manuals/r-release/…
-
R 中的一切都是对象。
is.vector(df)返回FALSE. -
函数不是向量。如果是,则闭包类型的对象可能是可子集的。 ;)