Unbin a data frame, i.e. replicate rows according to frequencies given in a vector. The function is intended to reconstruct raw data from data binned to classes.

unbin(x, freq)

Arguments

x

a vector or data frame with binned data

freq

vector of frequencies

Value

Vector or data frame with the same stucture as x with replicated elements or rows.

Examples

x <- data.frame(a=1:3, b=c("a", "b", "c"), freq=c(2, 5, 3)) unbin(x, x$freq)
#> a b freq #> 1 1 a 2 #> 1.1 1 a 2 #> 2 2 b 5 #> 2.1 2 b 5 #> 2.2 2 b 5 #> 2.3 2 b 5 #> 2.4 2 b 5 #> 3 3 c 3 #> 3.1 3 c 3 #> 3.2 3 c 3
zd <- 6:35 counts <- c(155, 0, 8, 12, 17, 35, 37, 66, 42, 39, 13, 4, 4, 8, 19, 36, 80, 205, 188, 219, 170, 104, 32, 13, 12, 0, 3, 0, 0, 0) observations <- unbin(zd, counts)