8

I don't understand the difference between is.atomic() and is.vector(). From my understanding, is.vector() returns TRUE for homogeneous 1D data structures. I believe is.atomic() returns TRUE for logicals, doubles, integers, characters, complexes, and raws...however, wouldn't is.vector() as well? So I thought perhaps the difference lies in its dimensions, but is.atomic() returned FALSE on a dataframe of doubles, which made me even more confused, ah...
我不明白 is.atomic()is.vector() 之间的区别。根据我的理解,is.vector() 为同构 1D 数据结构返回 TRUE。我相信 is.atomic() 对 logicals、doubles、integers、characters、complex 和 raws 返回 TRUE......但是,is.vector() 不也是吗?所以我想也许区别在于它的维度,但是 is.atomic() 在双精度的数据帧上返回了 FALSE,这让我更加困惑,啊......

Also, what is the difference between an atomic vector and a normal vector?
另外,原子向量和法向量有什么区别?

Thanks for your clarification!
感谢您的澄清!

CC BY-SA 3.0

2 Answers 2

9

Atomic vectors are a subset of vectors in R. In the general sense, a "vector" can be an atomic vector, a list or an expression. The language definition sort of defines vectors as "contiguous cells containing data". Also refer to help("is.vector") and help("is.atomic"), which explain when these return TRUE or FALSE.
原子向量是 R 中向量的子集。从一般意义上讲,“向量”可以是原子向量、列表或表达式。语言定义将向量定义为 “包含数据的连续单元格”。另请参阅 help(“is.vector”)help(“is.atomic”),它们解释了它们何时返回 TRUEFALSE

is.vector(list())
#[1] TRUE
is.vector(expression())
#[1] TRUE
is.vector(numeric())
#[1] TRUE

is.atomic(list())
#[1] FALSE
is.atomic(expression())
#[1] FALSE
is.atomic(numeric())
#[1] TRUE

Colloquially, we usually mean atomic vectors (possibly even with attributes) when we talk about vectors.
通俗地说,当我们谈论向量时,我们通常指的是原子向量(甚至可能带有属性)。

CC BY-SA 3.0
1

Vectors in R can have 2 structures, the first one, atomic vectors, and the second one, lists.
R 中的向量可以有 2 个结构,第一个是原子向量,第二个是列表。

If you create a new, empty vector, you can specify the mode to get an empty list vector(mode = "list") which returns the same as list().
如果你创建一个新的空 vector,你可以指定模式来获取一个空列表 vector(mode = “list”),它返回与 list() 相同的结果。

identical(vector(mode = "list"), list())
[1] TRUE

is.vector(vector(mode = "list")) returns [1] TRUE, whereas is.atomic(vector(mode = "list")) returns [1] FALSE.
is.vector(vector(mode = "list")) 返回 [1] TRUE,而 is.atomic(vector(mode = “list”)) 返回 [1] FALSE

CC BY-SA 3.0

Your Answer  您的答案

Not the answer you're looking for? Browse other questions tagged or ask your own question.