- 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

# 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 Questions & Answers
- 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 zeros in each column of a data.table object in R?
- How to find the percentage of missing values in each column of an R data frame?
- 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 frame in R?
- How to create a table of frequency for range of values in an R data frame column?
- How to find the percentage of missing values in an R data frame?
- How to find the percentage of zeros in each column of a matrix in R?
- How to find the percentage of each category in an R data frame column?
- How to find the number of values in a column of an R data frame that are not zero?
- How to find the unique values in a column of an R data frame?
- How to subset a data.table object using a range of values in R?
- How to find the column means of a column based on another column values that represent factor in an R data frame?
- Algorithm to sum ranges that lie within another separate range in JavaScript

Advertisements