dfidx: Data frames with indexes

View source: R/dfidx.R

dfidxR Documentation

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,
  name,
  position,
  ...
)

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

name

name of the idx column

position

position of the idx column

...

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

# the first two columns contain the index
mn <- dfidx(munnell)

# explicitely indicate the two indexes using either a vector or a
# list of two characters
mn <- dfidx(munnell, idx = c("state", "year"))
mn <- dfidx(munnell, idx = list("state", "year"))

# rename one or both indexes
mn <- dfidx(munnell, idnames = c(NA, "period"))

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

# use the name of the first index
mn <- dfidx(munnell, idx = "state", idnames = c("state", "year"))

# or an integer equal to the cardinal of the first index
mn <- dfidx(munnell, idx = 48, idnames = c("state", "year"))

# Indicate the values of the second index using the levels argument
mn <- dfidx(munnell, idx = 48, idnames = c("state", "year"),
            levels = 1970:1986)

# Nesting structure for one of the index
mn <- dfidx(munnell, idx = c(region = "state", president = "year"))

# Data in wide format
mn <- dfidx(munnell_wide, idx = c(region = "state"),
            varying = 3:36, sep = "_", idnames = c(NA, "year"))

# Customize the name and the position of the `idx` column
#dfidx(munnell, position = 3, name = "index")

dfidx documentation built on Sept. 11, 2024, 7:55 p.m.