Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_pibble

Coerce to a pibble panel data set object


Description

This function coerces a tibble, data.frame, or list to a pibble tibble by adding the .i, .t, and .d attributes to it.

Usage

as_pibble(x, .i = NULL, .t = NULL, .d = 1, .uniqcheck = FALSE, ...)

## S3 method for class 'tbl_df'
as_pibble(x, .i = NULL, .t = NULL, .d = 1, .uniqcheck = FALSE, ...)

## S3 method for class 'grouped_df'
as_pibble(x, .i = NULL, .t = NULL, .d = 1, .uniqcheck = FALSE, ...)

## S3 method for class 'data.frame'
as_pibble(x, .i = NULL, .t = NULL, .d = 1, .uniqcheck = FALSE, ...)

## S3 method for class 'list'
as_pibble(x, .i = NULL, .t = NULL, .d = 1, .uniqcheck = FALSE, ...)

Arguments

x

A data frame, tibble or list

.i

Quoted or unquoted variable(s) that identify the individual cases. If this is omitted, pibble will assume the data set is a single time series.

.t

Quoted or unquoted variable indicating the time. pmdplyr accepts two kinds of time variables: numeric variables where a fixed distance .d will take you from one observation to the next, or, if .d=0, any standard variable type with an order. Consider using the time_variable() function to create the necessary variable if your data uses a Date variable for time.

.d

Number indicating the gap in t between one period and the next. For example, if .t indicates a single day but data is collected once a week, you might set .d=7. To ignore gap length and assume that "one period ago" is always the most recent prior observation in the data, set .d=0. By default, .d=1.

.uniqcheck

Logical parameter. Set to TRUE to perform a check of whether .i and .t uniquely identify observations, and present a message if not. By default this is set to FALSE and the warning message occurs only once per session.

...

Other arguments passed on to individual methods.

Details

  • .i, Quoted or unquoted variable(s) indicating the individual-level panel identifier

  • .t, Quoted or unquoted variable indicating the time variable

  • .d, a number indicating the gap

Note that pibble does not require that .i and .t uniquely identify the observations in your data, but it will give a warning message (a maximum of once per session, unless .uniqcheck=TRUE) if they do not.

Examples

data(SPrail)
# I set .d=0 here to indicate that I don't care how large the gap
# between one period and the next is.
# If I want to use 'insert_date' for .t with a fixed gap between periods,
# I need to transform it into an integer first; see time_variable()
SP <- as_pibble(SPrail,
  .i = c(origin, destination),
  .t = insert_date,
  .d = 0
)
is_pibble(SP)
attr(SP, ".i")
attr(SP, ".t")
attr(SP, ".d")

data(Scorecard)
# Here, year is an integer, so I can use it with .d = 1 to
# indicate that one period is a change of one unit in year
# Conveniently, .d = 1 is the default
Scorecard <- as_pibble(Scorecard, .i = unitid, .t = year)
is_pibble(Scorecard)

pmdplyr

'dplyr' Extension for Common Panel Data Maneuvers

v0.3.3
MIT + file LICENSE
Authors
Nick Huntington-Klein [aut, cre] (<https://orcid.org/0000-0002-7352-3991>), Philip Khor [aut] (<https://orcid.org/0000-0002-8333-1256>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.