我有一个类似的数据集
sample value
A 0.2
B 0.25
C 0.51
D 0.91
我想将数据放入以下c(0,0.25,0.50,0.75,0.9(的自定义bin中,并找出bin中"sample"的频率。使用新的装箱数据,我想根据样本数量绘制一个值的直方图。感谢任何帮助,帮助我生产这些定制的箱子
也许你可以试试table
+cut
bin <- c(0, 0.25, 0.50, 0.75, 0.9)
> table(cut(df1$value,c(bin,Inf)))
(0,0.25] (0.25,0.5] (0.5,0.75] (0.75,0.9] (0.9,Inf]
2 0 1 0 1
或hist
> hist(df1$value,breaks = c(bin,Inf), plot = FALSE)
$breaks
[1] 0.00 0.25 0.50 0.75 0.90 Inf
$counts
[1] 2 0 1 0 1
$density
[1] 2 0 1 0 0
$mids
[1] 0.125 0.375 0.625 0.825 Inf
$xname
[1] "df1$value"
$equidist
[1] FALSE
attr(,"class")
[1] "histogram"