# HistDat In HistDat: Summary Statistics for Histogram/Count Data

```knitr::opts_chunk\$set(
collapse = TRUE,
comment = "#>"
)
```

First we need to import the package:

```library(HistDat)
```

Now, let's say that we have seen the number one 1000 billion times, the number two twice that, the number three the same as two, and the number four the same number of times as one.

If we turned this into a single vector with the true number of each observation, we would have a vector of length 6,000,000,000,000! It seems unlikely that this would even fit into RAM, and if it did, calculations would be very difficult.

```h = HistDat(
vals = 1:4,
counts = c(1e12, 2e12, 2e12, 1e12)
)
```

Now let's calculate some summary statistics, without using RAM we don't need!

```mean(h)
min(h)
length(h)
median(h)
```

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:

```h = HistDat(
vals = 1:4,
counts = c(1, 2, 2, 1)
)
as.vector(h)
```

## Try the HistDat package in your browser

Any scripts or data that you put into this service are public.

HistDat documentation built on April 6, 2021, 9:08 a.m.