![](/img/trans.png)
[英]R: How to create a new column for 90th quantile based off previous rows in a data frame grouped by another column?
[英]How to calculate the 90th percentile of a column corresponding to another column having same characters using R
df<-read. csv("input. csv")
df
So my dataframe df looks like this...
Name Time
Launch 10
Launch 20
Launch 30
Login 55
Login 69
Login 48
Login 74
Logout 29
Logout 13
基本上我想要的是在我的數據框中添加另一列,它應該容納列“時間”的90%,而列“名稱”
我的預期輸出應該看起來像..
Name 90thpercentile-_Time
Launch 90thpercentile(10,20,30)
Login 90thpercentile(55,69,48,74)
Logout 90thpercentile(29,13)
我通過使用分位數,聚合等函數在R上進行了很多嘗試,但沒有得到預期的結果。 有人可以幫忙嗎???
aggregate(df$Time, by=list(Name=df$Name), FUN=function(x) quantile(x, probs =0.9))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.