如何从列中获取第一个四分位数

问题描述 投票:0回答:2

我有一个数据框,其中有一列名为“平均值”。我只想从该列中获取第一个四分位数。我知道我可以使用四分位数(df)或摘要(df),但这给了我所有四分位数。我怎样才能获得第一个?

r statistics
2个回答
34
投票

你可以试试这个:

#sample data
Means <- runif(100)

#and this is how you get the first quartile
> summary(Means)[2]
1st Qu. 
 0.2325 

或者根据 Pascal 的评论使用函数

quantile

> quantile(Means, 0.25)
      25% 
0.2324663 

0
投票

要获取第一个四分位数的值,您可以这样做:

> quantile(Means)[["25%"]]
[1] 0.2209037
© www.soinside.com 2019 - 2024. All rights reserved.