Description Usage Arguments Value Examples
Generate raw data from a count table or a count data frame. A count table is a contingency table for only one factor. A count data frame is a data frame consisting of two columns: the first column contains all the different factor levels, and the second column, the corresponding counts.
1 | uncount(x)
|
x |
Table (i.e. the output of |
A vector whose length is equal to the sum of counts. It is a factor
if x
is a table. Otherwise if x
is a data frame, the class of
the return value is the same as the class of the first column of x
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | set.seed(12345)
x1 <- sort(rgeom(100, prob = 0.5))
y <- table(x1)
y
x2 <- uncount(y)
x2 <- as.integer(as.character(x2))
# More efficient, but harder to remember:
# x2 <- as.integer(levels(x2)[as.integer(x2)])
identical(x1, x2)
require(MASS)
x <- data.frame(label = c(1, 2, 3, 4, 6, 9),
count = c(4, 7, 4, 1, 1, 1))
x <- uncount(x)
res <- fitdistr(x, "Poisson")
res
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.