Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
unsorted
r
communitycreator

What is the is.unsorted() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The is.unsorted() function in R is used to check if a given object passed to it is not sorted. It returns TRUE if the object is not sorted and FALSE if otherwise.

Syntax

is.unsorted(x, na.rm = FALSE, strictly = FALSE)
Syntax for the is.unsorted() function

Parameter values

The is.unsorted() function takes the following parameter values:

  • x: This is any R object of numerical values.
  • na.rm: This takes the logical value (TRUE or FALSE) indicating whether the missing values be removed before checking or not.
  • strictly: This takes the logical value (TRUE or FALSE) indicating whether the check should be strictly increasing values or not.

Return value

The is.unsorted() function returns a length-one logical value.

Example

# creating R objects
a <- c( 1:10, 12:15, 20)
b <- w <- c(12:15, 1:10, 20)
# printing the R objects
a
b
# Checking if the objects are unsorted
is.unsorted(a)
is.unsorted(b)
Implementing the is.unsorted() function

Code explanation

  • Lines 2–3: We create R objects, a and b, containing numerical values.
  • Lines 6–7: We print the values of the objects, a and b.
  • Lines 10: We check to see if the objects are unsorted using the is.unsorted() function. We print the results to the console.

RELATED TAGS

function
unsorted
r
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring