Learn R Programming

DataCombine (version 0.2.21)

TimeExpand: Expands a data set so that it includes an observation for each time point in a sequence. Works with grouped data.

Description

Expands a data set so that it includes an observation for each time point in a sequence. Works with grouped data.

Usage

TimeExpand(data, GroupVar, TimeVar, begin, end, by = 1)

Arguments

data
a data frame.
GroupVar
the variable in data that signifies the group variable.
TimeVar
the variable in data that signifies the time variable. The sequence will be expanded between its minimum and maximum value if begin and end are not specified.
begin
numeric of length 1. Specifies beginning time point. Only relevant if end is specified.
end
numeric of length 1. Specifies ending time point. Only relevant if begin is specified.
by
numeric or character string specifying the steps in the TimeVar sequence. Can use "month", "year" etc for POSIXt data.

Examples

Run this code
Data <- data.frame(country = c("Cambodia", "Camnodia", "Japan", "Japan"),
                   year = c(1990, 2001, 1994, 2012))

ExpandedData <- TimeExpand(Data, GroupVar = 'country', TimeVar = 'year')

Run the code above in your browser using DataLab