- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if values in a column of an R data frame are increasingly ordered or not?
The values are increasingly ordered if the first value is less than the second, the second is less than the third, the third is less than the fourth, the fourth is less than the fifth, and so on. In base R, we have a function called is.unsorted that can help us to determine whether the values in a column of an R data frame are increasingly ordered or not. Check out the below examples to understand how it works.
Example1
> set.seed(3257) > x<-rpois(20,8) > df1<-data.frame(x) > df1
Output
x 1 9 2 8 3 8 4 7 5 10 6 2 7 7 8 7 9 7 10 9 11 10 12 6 13 9 14 9 15 9 16 11 17 12 18 8 19 10 20 12
Example
> is.unsorted(df1$x)
Output
[1] TRUE
Example2
> y<-rnorm(20,1,0.5) > df2<-data.frame(y) > df2
Output
y 1 0.5731483 2 1.2753959 3 1.3351612 4 1.9271030 5 1.0375696 6 0.4298899 7 1.2225022 8 0.8681973 9 0.8746253 10 1.4602984 11 0.4892610 12 1.4181656 13 0.4254027 14 0.9397925 15 -0.1129803 16 1.2659725 17 1.2444735 18 1.6010428 19 0.1310723 20 0.2720108
Example
> is.unsorted(df2$y)
Output
[1] TRUE
Example3
> z<-runif(20,2,5) > df3<-data.frame(z) > df3
Output
z 1 4.426558 2 2.405967 3 2.294161 4 4.629669 5 3.286604 6 4.836352 7 4.003845 8 2.456922 9 2.374872 10 3.216140 11 4.987071 12 4.713011 13 3.014407 14 2.792747 15 3.951100 16 3.023335 17 3.129816 18 3.688158 19 2.078943 20 2.323125
Example
> is.unsorted(df3$z)
Output
[1] TRUE
- Related Articles
- How to check if some specific columns of an R data frame are equal to a column or not?
- How to check if a value exists in an R data frame or not?
- How to check if a data frame column contains duplicate values in R?
- How to find the number of values in a column of an R data frame that are not zero?
- How to check whether a data frame exists or not in R?
- How to check if a column is categorical in R data frame?
- How to check whether a column exists in an R data frame?
- How to select positive values in an R data frame column?
- How to randomly replace values in an R data frame column?
- How to find the unique values in a column of an R data frame?
- How to concatenate column values and create a new column in an R data frame?
- How to replace missing values in a column with corresponding values in other column of an R data frame?
- How to check if all values in a vector are integer or not in R?
- How to find the sum of column values of an R data frame?
- How to check if a character column only contains alphabets in R data frame?

Advertisements