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...
Also, what is the difference between an atomic vector and a normal vector?
Thanks for your clarification!
An atomic vector is different from a one-dimensional array: an array has a dim attribute of length one while a vector has no such attribute. An atomic vector is also different from a list. The elements of a vector are all of the same types while a list can contain any arbitrary type.
atomic() function in R is used to check if an R object is atomic or not. When an R object is atomic it can be used to create atomic vectors. Note: R has six basic atomic vector types: logical, integer, real, complex, string (or character), and raw.
atomic is true for the atomic types ( "logical" , "integer" , "numeric" , "complex" , "character" and "raw" ) and NULL . Most types of objects are regarded as recursive.
Atomic data types are the object types that you can use to create atomic vectors. To check if any data object is atomic in R, use the is. atomic() function.
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
.
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.
Vectors in R can have 2 structures, the first one, atomic vectors, and the second one, lists.
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()
.
identical(vector(mode = "list"), list())
[1] TRUE
is.vector(vector(mode = "list"))
returns [1] TRUE
, whereas is.atomic(vector(mode = "list")) returns [1] FALSE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With