我必须计算给定值的四分位数,并使用R中的quartile()函数计算四分位数,如下所示
vc <- c(1,2,5,6,7,9,12,15,18,19,27)
quartiles <- quantile(vc, probs = seq(0,1,0.01))
上面代码的输出是
0% 1.0
1% 1.1
2% 1.2
3% 1.3
4% 1.5
.... and so on upto 100%. //this output is named vector
我想将这个名为vector的输出转换为具有列'quartile'和'pvalues'的数据帧,如下所示
quartile pvalues
0 1.0
1 1.1
2 1.2
3 1.3
4 1.4
.... so on upto 100.
我想转换0%,1%…在四分位列中作为整数的值和在pvalues列中作为向量的值。
我们可以使用
vc <- c(1,2,5,6,7,9,12,15,18,19,27)
quartiles <- quantile(vc, probs = seq(0,1,0.01))
df <- data.frame(names(quartiles), quartiles, row.names = NULL)
colnames(df) <- c("quartile", "pvalue")
df$quartile <- as.numeric(gsub("%","", df$quartile))
> df
quartile pvalue
1 0 1.0
2 1 1.1
3 2 1.2
4 3 1.3
5 4 1.4
6 5 1.5