- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 find the percentage of values that lie within a range in column of a data.table object in R?
To find the percentage of values that lie within a range in column of a data.table object in R, we can follow the below steps −
First of all, create a data.table object.
Then, use sum function along with extreme values for range and length function to find the percentage of values that lie within that range.
Example
Create the data.table object
Let’s create a data.table object as shown below −
library(data.table) x<-rnorm(30) DT<-data.table(x) DT
Output
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
x 1: -0.01820109 2: 0.09807795 3: 0.87645348 4: 0.22873684 5: 0.48448009 6: 0.13104149 7: -0.58816453 8: -0.06087622 9: 0.19032472 10: -0.39708670 11: 0.56044501 12: -1.42750377 13: -0.76757968 14: -0.85976410 15: -0.45661539 16: -0.12494892 17: -0.02593251 18: 0.64340403 19: 0.66718194 20: -0.93805129 21: -0.27078554 22: 0.91980427 23: 1.48243157 24: -0.52458819 25: 0.73368864 26: 0.11948186 27: -0.67115652 28: -0.70762527 29: -0.26249638 30: -0.22123573 x
Find the percentage of values that lie within a range
Using sum function along with the range that is 0.5 and 0.9 and length function to find the percentage of values that lie within this range −
library(data.table) x<-rnorm(30) DT<-data.table(x) sum(DT$x>0.5 & DT$x<0.9)/length(DT$x)
Output
[1] 0.1666667
- Related Articles
- How to find the percentage of values that lie within a range in R data frame column?
- How to find the percentage of values that lie within a range in a single column R matrix?
- How to find the percentage of each category in a data.table object column in R?
- How to find the percentage of zeros in each column of a data.table object in R?
- How to subset a data.table object using a range of values in R?
- How to repeat column values of a data.table object in R by number of values in another column?
- How to randomize column values of a data.table object for all columns in R?
- How to randomize column values of a data.table object for a set of columns in R?
- How to find the number of unique values for each column in data.table object in R?
- How to find the count of each category in a data.table object column in R?
- How to find the number of zeros in each column of a data.table object in R?
- How to find the index of values in data.table object column in R if they occur once?
- How to convert values greater than a threshold into 1 in column of a data.table object in R?
- How to add a column to data.table object in R?
- How to find the mean of a column summarized by other column names and common values in those columns in data.table object in R?

Advertisements