- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

If we have a list that contains numeric elements and we want to check whether the elements are greater than a certain value then as.numeric function can be used. The output of the function will be in 0/1 format where 0 represents FALSE and 1 represents TRUE. For example, if we have a list called LIST then to check whether elements in LIST are greater than 2 can be done as as.numeric(LIST>2).

List1<−list(1,2,2,2,4,1,2,5,5,2,3,5,2,2,2,2,5,5,8,9,6,5,5) List1

[[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 2 [[4]] [1] 2 [[5]] [1] 4 [[6]] [1] 1 [[7]] [1] 2 [[8]] [1] 5 [[9]] [1] 5 [[10]] [1] 2 [[11]] [1] 3 [[12]] [1] 5 [[13]] [1] 2 [[14]] [1] 2 [[15]] [1] 2 [[16]] [1] 2 [[17]] [1] 5 [[18]] [1] 5 [[19]] [1] 8 [[20]] [1] 9 [[21]] [1] 6 [[22]] [1] 5 [[23]] [1] 5

Checking whether elements in List1 are greater than 5 or not −

as.numeric(List1>5)

[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0

List2<−list(4,7,5,4,1,2,5,2,3,6,5,7,7,1,1,2,5,5,9,2) List2

[[1]] [1] 4 [[2]] [1] 7 [[3]] [1] 5 [[4]] [1] 4 [[5]] [1] 1 [[6]] [1] 2 [[7]] [1] 5 [[8]] [1] 2 [[9]] [1] 3 [[10]] [1] 6 [[11]] [1] 5 [[12]] [1] 7 [[13]] [1] 7 [[14]] [1] 1 [[15]] [1] 1 [[16]] [1] 2 [[17]] [1] 5 [[18]] [1] 5 [[19]] [1] 9 [[20]] [1] 2

Checking whether elements in List2 are greater than 2 or not −

as.numeric(List2>2)

[1] 1 1 1 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 1 0

- Related Questions & Answers
- Check if any value in an R vector is greater than or less than a certain value.
- How to check whether a column value is less than or greater than a certain value in R?
- Check which element in a masked array is greater than a given value
- Replace all values in an R data frame if they are greater than a certain value.
- How to calculate the number of elements greater than a certain value in a vector in R?
- How to create a plot using ggplot2 by including values greater than a certain value in R?
- How to subset an R data frame if numerical column is greater than a certain value for a particular category in grouping column?
- How to subset rows of an R data frame if any columns have values greater than a certain value?
- How to subset rows of an R data frame if all columns have values greater than a certain value
- How to create a subset of matrix in R using greater than or less than a certain value of a column?
- How to find the frequency of values greater than or equal to a certain value in R?
- C# program to check if all the values in a list that are greater than a given value
- Python program to check if all the values in a list that are greater than a given value
- How to subset an R data frame if one of the supplied grouping values is found and numerical column value is greater than a certain value?
- Find the combination of columns for correlation coefficient greater than a certain value in R

Advertisements