Learn R Programming

mefa (version 1.1-4)

inflate: Inflate Data Frame According to Integer Vector

Description

This function inflates a data frame according to a column containing integers, by repeating each rows as many times as the integer value. This is an internal function used by the function xcount converting an object of 'sscount' into 'xcount'.

Usage

inflate(factors, count)

Arguments

factors
a data frame or matrix used. Rows in factors are repeated as many times as the value of respective value of count. Thus, number of rows in factor must equal the length of count.
count
a numeric (integer) vector with the same length as number of rows in factors.

Value

  • A matrix with columns as in factors, and rows according to sum of count.

See Also

sscount, xcount

Examples

Run this code
ss <- data.frame(
cbind(
c("sample1","sample1","sample2","sample2","sample3","sample4"),
c("species1","species1","species1","species2","species3","zero.count"),
c("male","female","male","female","male","male")
),
c(1, 2, 10, 3, 4, 1)
)
colnames(ss) <- c("sample.id", "species.id", "gender", "catch")

inflate(ss[,1:3], ss[,4])
inflate(ss[,1:3], c(1:6))
inflate(ss[,1:3], rep(2, 6))

Run the code above in your browser using DataLab