When entering this in the R console:
1 + 2
1 + 2
A = matrix(c(1,-2,3,14),2,2)
Basically, for checking the data types in R, you can use several functions contained in the
Now, focusing on your explicit questions:
> is.vector(1 + 2)  TRUE > is.atomic(1 + 2)  TRUE > length(1 + 2)  1
Consequently, the result is stored in a vector of length 1.
> is.vector(c(1,-2,3,14))  TRUE > is.atomic(c(1,-2,3,14))  TRUE
c(...) initializes a vector object, obviously the data type is a vector.
> is.matrix(A)  TRUE > is.vector(A)  FALSE > is.atomic(A)  TRUE > is.vector(A[1, ])  TRUE > is.atomic(A[1, ])  TRUE > is.matrix(A[1, ])  FALSE > is.vector(A[, 2])  TRUE > is.atomic(A[, 2])  TRUE > is.matrix(A[, 2])  FALSE
And finally, subsetting a matrix row-wise or column-wise returns also a vector and not a matrix.
For checking for a scalar, please refer to this question.
As mentioned by @Rich Scriven, there are two types of vectors in R: atomic and generic vectors. Indeed, the function
is.vector(x) used in above examples returns
TRUE for lists as well. Besides that,
is.atomic(x) checks for atomic vectors which contain data of one primitive data type (logical, integer, real, complex, character, or raw) only. Additionally, I have added the respective
is.atomic(x) function calls in above examples as well.