Home > Blockchain >  How to identify quartiles
How to identify quartiles

Time:12-09

Which age are in the bottom 25% of Glucose and the top 25% of Glucose?

enter image description here

to identify the top 25% and bottom I do this

x<- quantile(db$Glucose,0.25)
print(x)
y<- quantile(db$Glucose,0.75)
print(y)

I am a beginner in R I try if statement but I can't extract the age relative to a specific condition of other columns

CodePudding user response:

One way to do this is subset the data based on the quantile of glucose for age. Here I am going to use the mtcars data to demonstrate.

mtcars$hp[mtcars$mpg < quantile(mtcars$mpg,.25)]

In the code above I want to know what the hp is when mpg is in the lower 25%ile of the dataset. In this example hp would be replaced with age and mpg would be replaced with glucose.

You can also write it in two steps if it is easier to read:

x <- quantile(mtcars$mpg, .25)

mtcars$hp[mtcars$mpg < x]

CodePudding user response:

x<- quantile(db$Glucose,0.25)
print(x)
y<- quantile(db$Glucose,0.75)
print(y)

new_data<- db[db$Glucose<x, ]
a<- new_data$Age
new_data<- db[db$Glucose>y, ]
b<- new_data$Age
c(a,b)`enter code here`
  •  Tags:  
  • r
  • Related