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

dfidx

Data frames with indexes


Description

data frames for which observations are defined by two (potentialy nested) indexes and for which series have thefore a natural tabular representation

Usage

dfidx(
  data,
  idx = NULL,
  drop.index = TRUE,
  as.factor = NULL,
  pkg = NULL,
  fancy.row.names = FALSE,
  subset = NULL,
  idnames = NULL,
  shape = c("long", "wide"),
  choice = NULL,
  varying = NULL,
  sep = ".",
  opposite = NULL,
  levels = NULL,
  ranked = FALSE,
  ...
)

Arguments

data

a data frame

idx

an index

drop.index

if TRUE (the default), remove the index series from the data.frame as stand alone series

as.factor

should the indexes be coerced to factors ?

pkg

if set, the resulting dfidx object is of class c("dfidx_pkg", "dfidx") which enables to write specific classes

fancy.row.names

if TRUE, fancy row names are computed

subset

a logical which defines a subset of rows to return

idnames

the names of the indexes

shape

either wide or long

choice

the choice

varying, sep

relevant for data sets in wide format, these arguments are passed to reshape

opposite

return the opposite of the series

levels

the levels for the second index

ranked

a boolean for ranked data

...

further arguments

Details

Indexes are stored as a data.frame column in the resulting dfidx object

Value

an object of class "dfidx"

Author(s)

Yves Croissant

Examples

data("TravelMode", package = "AER")

# the first two columns contain the index

TM1 <- dfidx(TravelMode)

# explicitely indicate the two indexes using either a vector or a
# list of two characters

TM2 <- dfidx(TravelMode, idx = c("individual", "mode"))

TM3 <- dfidx(TravelMode, idx = list("individual", "mode"))

# rename one or both indexes

TM3b <- dfidx(TravelMode, idnames = c(NA, "trmode"))

# for balanced data (with observations ordered by the first, then
# by the second index

# use the name of the first index

TM4 <- dfidx(TravelMode, idx = "individual", idnames = c("individual", "mode"))

# or an integer equal to the cardinal of the first index

TM5 <- dfidx(TravelMode, idx = 210, idnames = c("individual", "mode"))

# Indicate the values of the second index using the levels argument

TM5b <- dfidx(TravelMode, idx = 210, idnames = c("individual", "mode"),
levels = c("air", "train", "bus", "car"))

# Nesting structure for one of the index

data("JapaneseFDI", package = "mlogit")
JapaneseFDI <- dplyr::select(JapaneseFDI, 1:8)
JP1b <- dfidx(JapaneseFDI, idx = list("firm", c("region", "country")),
idnames = c("japf", "iso80"))

# Data in wide format

data("Fishing", package = "mlogit")
Fi <- dfidx(Fishing, shape = "wide", varying = 2:9, idnames = c("chid", "alt"))

dfidx

Indexed Data Frames

v0.0-4
GPL (>= 2)
Authors
Yves Croissant [aut, cre]
Initial release
2021-02-02

We don't support your browser anymore

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