R Error in sort.int(x, na.last, decreasing, …) : ‘x’ must be atomic (2 Examples)

In this article you’ll learn how to handle the “Error in sort.int(x, na.last = na.last, decreasing = decreasing, …) : ‘x’ must be atomic” in the R programming language.

Creation of Exemplifying Data

x <- list(1:5,                      # Constructing example list
          3:1,
          5)
x                                   # Displaying example list
# [[1]]
# [1] 1 2 3 4 5
# 
# [[2]]
# [1] 3 2 1
# 
# [[3]]
# [1] 5

Example 1: Replicating the Error in sort.int(x, na.last = na.last, decreasing = decreasing, …) : ‘x’ must be atomic

sort(x)                             # Sorting list does not work

Example 2: Solving the Error in sort.int(x, na.last = na.last, decreasing = decreasing, …) : ‘x’ must be atomic

sort(unlist(x))                     # Sorting vector works fine
# [1] 1 1 2 2 3 3 4 5 5

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