GEMINI-Medicine / Rgemini

A custom R package that provides a variety of functions to perform data analyses with GEMINI data
https://gemini-medicine.github.io/Rgemini/
Other
3 stars 0 forks source link

Make quartiles/quintiles/deciles of variables #89

Open shijiaSMH opened 6 months ago

shijiaSMH commented 6 months ago

Motivation

Continuous variables are commonly needed to be broken down into quartiles/quintiles/deciles for descriptive analysis.

Skeleton code ideas

Quartile ex code - quartiles

quartile <- function(x){
  cut(x, breaks = c(-Inf, quantile(x, probs = c(0.25, 0.5, 0.75)), Inf), labels = 1:4)
}
loffleraSMH commented 4 months ago

Can we make this function a bit more flexible to allow for creation of quintiles/deciles etc. as well? I.e., the function should accept an input (could be numeric, e.g., 4 for quartiles, 5 for quintiles etc.) and then the probs/labels are adjusted accordingly.

shijiaSMH commented 4 months ago

Thx Anne, your suggestion makes sense, quickly editing this issue right now :)