Learn R Programming

bsearchtools (version 0.0.59)

DFI: Create a data.frame (or matrix) with indexes

Description

Turn a data.frame (or matrix) object into a DFI object allowing faster lookups on indexed columns (indexed column to be intended as DB indexes).

Usage

DFI(DF, indexes.col.names=colnames(DF)) as.DFI(DF, indexes.col.names=colnames(DF)) # exactly the same as DFI() is.DFI(x) "print"(x, ...)

Arguments

DF
A data.frame or matrix object (must have column names defined).
indexes.col.names
The column names for which we want to create the indexes. Only integer,numeric,logical and character are supported, so be careful since data.frame by default turns strings into factors (see data.frame stringsAsFactors argument)
x
A DFI object.
...
optional arguments passed to inner print methods of data.frame and matrix .

Value

An object with class "DFI"

Details

Basically, DFI() function creates a wrapper of DF. This wrapper contains the original data.frame or matrix plus the necessary indexes data and the class of the wrapped object. These extra data will be used to perform faster lookups (in DFI.subset function) and can be extracted using the appropriate functions DFI.unWrap, DFI.indexes, DFI.getIndex.

See Also

DFI.subset DFI.unWrap DFI.indexes DFI.getIndex

Examples

Run this code

DF <- data.frame(Foo=c(3,5,7,1,5,8,7,10),
                 Bar=c("A","B","B","C","B","B","C","A"),
                 Baz=c(TRUE,FALSE),
                 stringsAsFactors=FALSE)
DFIobj <- DFI(DF, c("Foo","Bar")) # create a DFI from DF with indexes on "Foo" and "Bar" columns

Run the code above in your browser using DataLab