Description Usage Arguments Value Author(s) References Examples
Expands (replicates) the rows of a data.frame
or data.table
, either by a
fixed number, a specified vector, or a value contained in one of the columns
in the source data.frame
or data.table
.
1 | expandRows(dataset, count, count.is.col = TRUE, drop = TRUE)
|
dataset |
The input |
count |
The numeric vector of counts OR the column from the
dataset that contains the count data. If |
count.is.col |
Logical. Is the |
drop |
Logical. If |
A data.frame
or data.table
, depending on the input.
Ananda Mahto
http://stackoverflow.com/a/19519828/1270695
1 2 3 4 5 6 7 8 9 10 11 12 | mydf <- data.frame(x = c("a", "b", "q"),
y = c("c", "d", "r"),
count = c(2, 5, 3))
library(data.table)
DT <- as.data.table(mydf)
mydf
expandRows(mydf, "count")
expandRows(DT, "count", drop = FALSE)
expandRows(mydf, count = 3) ## This takes values from the third column!
expandRows(mydf, count = 3, count.is.col = FALSE)
expandRows(mydf, count = c(1, 5, 9), count.is.col = FALSE)
expandRows(DT, count = c(1, 5, 9), count.is.col = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.