简体   繁体   中英

R: a function to calculate counts of a series within a specified percentile range

I can get what I want using the following functions, but I would like to know any advanced ways to do what I want -- calculating counts of a series within a specified percentile range

age <- 0:100
tile <- quantile(age, c(0.28, 0.63))
counts <- length(age[age > tile[1] & age < tile[2]])

Thanks a lot.

I'm not sure what you mean by "advanced way", but here's a suggestion

age <- 0:100
tile <- quantile(age, c(0, 0.28, 0.63, 1))
counts <- summary(cut(age, tile, include.lowest = T))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM