简体   繁体   English

计算R中的运行百分比

[英]Calculating Running Percentile in R

I'm trying to calculate the percentiles from 1:i in a column. 我正在尝试从一列中的1:i计算百分位数。 For example, for the nth data point, calculate the percentile only using the first n values. 例如,对于第n个数据点,仅使用前n个值计算百分位。

I have tried using quantile , but can't seem to figure out how to generalize it. 我试过使用quantile ,但似乎无法弄清楚如何将其推广。

mydata <- c(1, 25, 43, 2, 5, 17, 40, 15, 12, 8)

perc.fn <- function(vec, n){
(rank(vec[1:n], na.last=TRUE) - 1)/(length(vec[1:n])-1)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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