JaehyunSong/RBook

atomic vectorの説明

Opened this issue · 0 comments

この章ではRにおけるデータ型について説明する。第[-@sec-datastructure]章で説明するデータ「構造」とデータ「型」は異なる概念なので、混同しないようにしてほしい。次章でも説明するが、Rにおけるデータの最小単位はベクトルである。`c(1, 2, 3, 4, 5)``c("Yanai", "Song", "Hadley")`がベクトルであることは(ここまで読んできた読者には)明らかだが、`30``"R"`もベクトルなのだ。要素が1つのみのベクトルは原子ベクトル (atomic vector) とも呼ばれるが、その性質は要素が2つ以上のベクトルと何ら変わらない。

↑の原子ベクトルの説明について、「長さ1のベクトルが原子ベクトル」と読めると思うのですが、実際にはそうではなくlistではない「内部のタイプが一つ(atomic)であるベクトル」が原子ベクトルだと認識しています。
例えば以下のような説明があります。

https://adv-r.hadley.nz/vectors-chap.html

Vectors come in two flavours: atomic vectors and lists. They differ in terms of their elements’ types: for atomic vectors, all elements must have the same type; for lists, elements can have different types. While not a vector, NULL is closely related to vectors and often serves the role of a generic zero length vector. This diagram, which we’ll be expanding on throughout this chapter, illustrates the basic relationships: