Check whether a Data Object is a Vector in R (2 Examples)

In this tutorial, I’ll demonstrate how to check whether an object is a vector in the R programming language.

Creation of Example Data

lst <- list(letters[5:1],           # Creating a list object
            1:7,
            "abc")
lst
# [[1]]
# [1] "e" "d" "c" "b" "a"
# 
# [[2]]
# [1] 1 2 3 4 5 6 7
# 
# [[3]]
# [1] "abc"

Example 1: Test if Object ist a Vector Using is.vector() Function

is.vector(lst)                      # Unexpected output
# [1] TRUE

Example 2: Test if Object ist a Vector Using is.vector() & is.atomic() Functions

is.vector(lst) && is.atomic(lst)    # Expected output
# [1] FALSE

Further Resources & Related Articles

Here, you can find some further resources that are related to the topic of this post:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top