- 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 find the percentage of values that lie within a range in R data frame column?
To find the percentage of values that lie within a range in R data frame column, we can follow the below steps −
First of all, create a data frame.
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 frame
Let’s create a data frame as shown below −
Var<-sample(1:100,30) df<-data.frame(Var) df
Output
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
Var 1 39 2 40 3 96 4 37 5 97 6 23 7 35 8 47 9 60 10 63 11 74 12 91 13 6 14 54 15 5 16 90 17 68 18 32 19 83 20 29 21 100 22 52 23 26 24 16 25 10 26 65 27 55 28 84 29 92 30 15
Find the percentage of values that lie within a range
Using sum function along with the range that is 10 and 91 and length function to find the percentage of values that lie within this range −
Var<-sample(1:100,30) df<-data.frame(Var) sum(df$Var>10 & df$Var<91)/length(df$Var)
Output
[1] 0.8
- Related Articles
- How to find the percentage of values that lie within a range in a single column R matrix?
- How to find the percentage of values that lie within a range in 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 missing values in an R data frame?
- How to find the percentage of zeros in each column of a data frame in R?
- How to find the percentage of each category in an R data frame column?
- How to find the unique values in a column of an R data frame?
- How to select rows based on range of values of a column in an R data frame?
- How to create a table of frequency for range of values in an R data frame column?
- How to find the sum of column values of an R data frame?
- How to find the column means of a column based on another column values that represent factor in an R data frame?
- How to find the number of values in a column of an R data frame that are not zero?
- How to find the sum of squared values of an R data frame column?
- How to convert a data frame column to date that contains integer values in R?
- How to find the number of non-empty values in an R data frame column?

Advertisements