First we need to import the package:
library(HistDat)
Now, let’s say that we have seen the number one 10,000 times, the number two 20,000 times etc.
If we turned this into a single vector with the true number of each observation, we would have a vector of length 60,000! That would use a lot of RAM, and we don’t really need to do that
= HistDat(
h vals = 1:4,
counts = c(10000, 20000, 20000, 10000)
)
Now let’s calculate some summary statistics, without using RAM we don’t need!
mean(h)
#> [1] 2.5
min(h)
#> [1] 1
length(h)
#> [1] 60000
median(h)
#> [1] 2.5
We actually can convert a hist_dat
object into a 1-D vector, which is reasonable if we only have a small number of counts:
= HistDat(
h vals = 1:4,
counts = c(1, 2, 2, 1)
)as.vector(h)
#> [1] 1 2 2 3 3 4