Learn R Programming

ForecastFramework (version 0.10.3)

IncidenceMatrix: IncidenceMatrix

Description

A class for storing a matrix and relevant metaData.

Arguments

Fields

cellData

A list of metadata associated with the cells of the data.

cnames

The names of columns in the data.

colData

A list of metadata associated with the columns of the data.

frame

A data.frame representation of the IncidenceMatrix. The frame contains all rows/columns as rows of the data frame, and the rows, columns, values and all metadata types as columns. This is similar to the melt function.

mat

This is the matrix. For extensibility, it cannot be written to directly and must be modified through methods.

metaData

Any data not part of the main data structure.

ncol

The number of columns in the data.

nrow

The number of rows in the data

rnames

The names of rows in the data.

rowData

A list of metadata associated with the columns of the data.

Methods

addColumns(columns)

This function adds empty columns to the right side of the data.

addRows(rows)

This function adds empty rows to the data.

as_sts(pop_name = 'pop',freq_name = 'freq',start_name = 'start',epoch_name = 'epoch',map_name = 'map',neighbourhood_name = 'neighbourhood')

Convert this object to an sts object with as much information as possible

debug(string)

A function for debugging the methods of this class. It calls the browser command. In order for methods to opt into to debugging, they need to implement the following code at the beginning: if(<method_name> %in% private$.debug){browser()}. This method exists, because the debugger is not always intuitive when it comes to debugging R6 methods.

diff(lag = 1,mutate=TRUE)

This function replaces the matrix value at column i with the difference. between the values at columns i and (i-lag).

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

head(k,direction=2,mutate=TRUE)

Select the last k slices of the data in dimension direction.

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

initialize(data=matrix(),metaData=list(),rowData=list(),colData=list(),cellData = list())

Create a new IncidenceMatrix object from its components.

lag(indices,mutate=TRUE,na.rm=FALSE)

This function replaces the current matrix with a new matrix with one column for every column, and a row for every row/index combination. The column corresponding to the row and index will have the value of the original matrix in the same row, but index columns previous. This shift will introduce NAs where it passes off the end of the matrix.

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

lead(indices,mutate=TRUE,na.rm=FALSE)

This function replaces the current matrix with a new matrix with one column for every column, and a row for every row/index combination. The column corresponding to the row and index will have the value of the original matrix in the same row, but index columns ahead.

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

mutate(rows,cols,data)

This function is a way to modify the data as though it were a matrix.

scale(f,mutate=TRUE)

This function rescales each element of our object according to f

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

subset(rows,cols,mutate=TRUE)

Select the data corresponding to the rows rows and the columns columns. rows and columns can be either numeric or named indices.

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

tail(k,direction=2,mutate=TRUE)

Select the last k slices of the data in dimension direction.

Value

If mutate=FALSE, a clone of this object will run the method and be returned. Otherwise, there is no return.

undebug(string)

A function for ceasing to debug methods. Normally a method will call the browser command every time it is run. This command will stop it from doing so.

See Also

Inherits from : AbstractIncidenceMatrix

Examples

Run this code
# NOT RUN {
data = IncidenceMatrix$new(matrix(1:9,3,3))
data$mat
data$nrow
data$ncol
data$colData = list(1:3,letters[1:3])
data$colData
data$addColumns(2)
data$colData
data$mat
data$diff(1)
data$mat
data$lag(1)
data$mat
data$head(1,1)
data$mat
data$tail(2,2)
data$mat
data$mutate(data=3)
data$mat
data = IncidenceMatrix$new(matrix(1:9,3,3))
data$scale(function(x){x^2},mutate=FALSE)$mat
data$mat
data$subset(rows=1,cols=2)
data$mat
# }

Run the code above in your browser using DataLab