Learn R Programming

incidence (version 1.7.4)

as.data.frame.incidence: Conversion of incidence objects

Description

These functions convert incidence objects into other classes.

Usage

# S3 method for incidence
as.data.frame(x, ..., long = FALSE)

as.incidence(x, ...)

# S3 method for matrix as.incidence( x, dates = NULL, interval = NULL, standard = TRUE, isoweeks = standard, ... )

# S3 method for data.frame as.incidence(x, dates = NULL, interval = NULL, isoweeks = TRUE, ...)

# S3 method for numeric as.incidence(x, dates = NULL, interval = NULL, isoweeks = TRUE, ...)

Arguments

x

An incidence object, or an object to be converted as incidence (see details).

...

Further arguments passed to other functions (no used).

long

A logical indicating if the output data.frame should be 'long', i.e. where a single column containing 'groups' is added in case of data computed on several groups.

dates

A vector of dates, each corresponding to the (inclusive) lower limit of the bins.

interval

An integer indicating the time interval used in the computation of the incidence. If NULL, it will be determined from the first time interval between provided dates. If only one date is provided, it will trigger an error.

standard

A logical indicating whether standardised dates should be used. Defaults to TRUE.

isoweeks

Deprecated. Use standard.

Author

Thibaut Jombart thibautjombart@gmail.com, Rich Fitzjohn

Details

Conversion to incidence objects should only be done when the original dates are not available. In such case, the argument x should be a matrix corresponding to the $counts element of an incidence object, i.e. giving counts with time intervals in rows and named groups in columns. In the absence of groups, a single unnamed columns should be given. data.frame and vectors will be coerced to a matrix.

See Also

the incidence() function to generate the 'incidence' objects.

Examples

Run this code
## create fake data
data <- c(0,1,1,2,1,3,4,5,5,5,5,4,4,26,6,7,9)
sex <- sample(c("m","f"), length(data), replace=TRUE)

## get incidence per group (sex)
i <- incidence(data, groups = sex)
i
plot(i)

## convert to data.frame
as.data.frame(i)

## same, 'long format'
as.data.frame(i, long = TRUE)



## conversion from a matrix of counts to an incidence object
i$counts
new_i <- as.incidence(i$counts, i$dates)
new_i
all.equal(i, new_i)

Run the code above in your browser using DataLab