R语言 创建数据集的量值–quantile()函数
R语言中的 quantile() 函数用于在一个数据集中创建概率为[0, 1]的样本量级。例如,第一个量化指标在0.25[25%]
,第二个在0.50[50%]
,第三个在0.75[75%]
。
语法: quantile(x)
参数:
x: 数据集
例1 :
# R program to create
# quantiles of a data set
# Create a data frame
d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"),
age = c(7, 5, 9, 16),
ht = c(46, NA, NA, 69),
school = c("yes", "yes", "no", "no") )
# Calling quantile() Function
quantile(d$age)
输出
0% 25% 50% 75% 100%
5.00 6.50 8.00 10.75 16.00
例2 :
# R program to create
# quantiles of a data set
# Calling pre-defined data set
BOD
# Calling quantile() Function
quantile(BODdemand)
quantile(BODTime)
输出
Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8
0% 25% 50% 75% 100%
8.300 11.625 15.800 18.250 19.800
0% 25% 50% 75% 100%
1.00 2.25 3.50 4.75 7.00