Learn R Programming

mefa (version 3.2-9)

rep.data.frame: Inflate (repeat) a Data Frame

Description

The function inflates a data frame based on count values in a vector corresponding the rows.

Usage

# S3 method for data.frame
rep(x, ...)

Value

A data frame with columns as in the original (x) and e.g. sum(times) number of rows.

Arguments

x

a matrix or data frame, but can be a vector.

...

arguments passed to the function rep, i.e. times, length.out and each (see explanation there).

Author

P\'eter S\'olymos, solymos@ualberta.ca

Details

Each rows of the data frame x will be repeated as many times as the corresponding value in e.g. the vector times. This function is called internally by the function stcs.

References

S\'olymos P. (2008) mefa: an R package for handling and reporting count data. Community Ecology 9, 125--127.

S\'olymos P. (2009) Processing ecological data in R with the mefa package. Journal of Statistical Software 29(8), 1--28. tools:::Rd_expr_doi("10.18637/jss.v029.i08")

http://mefa.r-forge.r-project.org/

See Also

stcs

Examples

Run this code
x <- data.frame(sample = LETTERS[c(1,1,2,2,3)],
    species = letters[c(5,5,5,6,7)],
    count = c(1,2,10,3,4), segment = letters[c(8,9,8,9,8)])
x
rep(x[,c(1,2,4)], times = x[,3])
rep(x[,c(1,2,4)], each = 2)

Run the code above in your browser using DataLab