Learn R Programming

wlsd (version 1.0.1)

long2count: Longitudinal to Count format

Description

Aggregates longitudinal data into a count format data set.

Usage

long2count(data, id, event = NULL, state = NULL, FUN, ...)

Value

A data frame aggregated into count format.

Arguments

data

A data frame with relevant columns.

id

A character string of the identification variable name in data.

event

The name(s) of the event column(s) in data to be tallied. The name(s) is required to be supplied as a string. The elements of this argument are assumed to be numeric and are summed for each identification level from id.

state

The name of the state variable in data. This argument is used if the event of interest is a numeric or non-numeric series of states. Each of these levels will be tallied for each level of the id.

FUN

The summary function to be applied to all time-depentent columns (wrapper for argument in stats::aggregate). If nothing is supplied, then mean will be used.

...

Additional arguments supplied to stats::aggregate.

Details

The returned data frame aggregates any time-depended values based on row-wise changes within id groups. New columns include event.counts which represents the sum total of values in the event column for each level of id or the sum total of levels of the state column if supplied as well as the count.weight column which sums the number of rows for each level of id.

Examples

Run this code
# if the "event" column should be summed
long2count(long_data, id = "id", event = "event")
# if the "event" column contains levels that should be summed separately
long2count(long_data, id = "id", state = "event")

Run the code above in your browser using DataLab