methods.dfidx: Methods for dfidx

methods.dfidxR Documentation

Methods for dfidx

Description

A dfidx object is a data frame with a "sticky" data frame column which contains the indexes. Specific methods of functions that extract lines and/or columns of a data frame are provided : [, [[, $,⁠[<-⁠, ⁠[[<-⁠ and ⁠$<-⁠. Moreover, methods are provided for base::transform and base::subset in order to easily generate new variables and select some rows and columns of a dfidx oject. An organize function is also provided to sort a dfidx object using one or several series.

Usage

## S3 method for class 'dfidx'
x[i, j, drop]

## S3 method for class 'dfidx'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

## S3 method for class 'dfidx'
print(x, ..., n = NULL)

## S3 method for class 'dfidx'
head(x, n = NULL, ...)

## S3 method for class 'dfidx'
x[[y]]

## S3 method for class 'dfidx'
x$y

## S3 replacement method for class 'dfidx'
object$y <- value

## S3 replacement method for class 'dfidx'
object[[y]] <- value

## S3 method for class 'xseries'
print(x, ..., n = NULL)

## S3 method for class 'idx'
print(x, ..., n = NULL)

## S3 method for class 'dfidx'
mean(x, ...)

## S3 method for class 'dfidx'
transform(`_data`, ...)

## S3 method for class 'dfidx'
subset(x, subset, select, drop = FALSE, drop.unused.levels = TRUE, ...)

organize(x, ...)

Arguments

x, object, _data

a dfidx object

i

the row index (or the column index if j is not used)

j

the column index

drop

if TRUE a vector is returned if the result is a one column data.frame

row.names, optional

arguments of the generic as.data.frame method, not used

...

further arguments

n

the number of rows for the print method

y

the name or the position of the series one wishes to extract

value

the value for the replacement method

subset, select

see base::subset

drop.unused.levels

passed to dfidx::dfidx

Value

as.data.frame and mean return a data.frame, [[ and $ a vector, [ either a dfidx or a vector, ⁠$<-⁠ and ⁠[[<-⁠ modify the values of an existing column or create a new column of a dfidx object. transform, subset and organize return a dfidx object. print is called for its side effect.

Author(s)

Yves Croissant

Examples

mn <- dfidx(munnell)
# extract a series (returns as a xseries object)
mn$gsp
# or
mn[["gsp"]]
# extract a subset of series (returned as a dfidx object)
mn[c("gsp", "unemp")]
# extract a subset of rows and columns
mn[mn$unemp > 10, c("utilities", "water")]
# dfidx, idx and xseries have print methods as (like tibbles), a n
# argument
print(mn, n = 3)
print(idx(mn), n = 3)
print(mn$gsp, n = 3)
# a dfidx object can be coerced to a data.frame
as.data.frame(mn)
# transform, subset and organize are usefull methods/function to
# create new series, select a subset of lines and/or columns and to
# sort the `dfidx` object using one or several series
transform(mn, gsp70 = ifelse(year == 1970, gsp, 0))
subset(mn, gsp > 200000, select = c("gsp", "unemp"))
subset(mn, 1:20, select = c("gsp", "unemp"))
organize(mn, year, unemp)

dfidx documentation built on Aug. 8, 2025, 7:10 p.m.