> x=c(1,2,3,4,5)
> x1=list(n1=1,n2=2,n3=x)
> is.vector(x1)
[1] TRUE
> is.list(x1)
[1] TRUE
From ?is.vector
If mode = "any", is.vector may return TRUE for the atomic modes, list and expression.
You can specify the mode
if you do not want is.vector
to return TRUE
for a list
> is.vector(x1, mode='numeric')
[1] FALSE
> is.vector(x, mode='numeric')
[1] TRUE
A vector in R is an ordered collection of stuff. Stuff in this case is
> mode(x1)
[1] "list"
from the help file
is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names.
> attributes(x1)
$names
[1] "n1" "n2" "n3"
if we were to give x1 another attribute:
levels(x1)<-1:3
> x1
$n1
[1] 1
$n2
[1] 2
$n3
[1] 1 2 3 4 5
attr(,"levels")
[1] 1 2 3
> is.list(x1)
[1] TRUE
> is.vector(x1)
[1] FALSE
it would still be a list but not now a vector
From A brief history of S "The basic data structure in S is a vector of likeelements: numbers, character strings, or logical val ues. Although the notion of an attribute for an S object wasn't clearly implemented until the 1988 release, from the beginning S recognized that the primary vector of data was often accompanied by other values that described special properties of the data. For example, a matrix is just a vector of data along with an auxil iary vector named Dim that tells the dimensionality (number of rows and columns). Similarly, a time series has a Tsp attribute to tell the start time, end time, and number of observations per cycle. These vectors with attributes are known as vector structures, and this distinguishes S from most other systems."
Presumably it is similar in R which is an implementation of S so these vector structures are not designated as vectors.
> is.atomic(x1)
[1] FALSE
From the R language definition, lists are generic vectors, but not atomic vectors.