tableMatrix: tableMatrix constructor

Description Usage Arguments Details Value See Also Examples

Description

tableMatrix constructor, creates tableMatrix object from a list of data.frames or data.tables. It is useful for datasets with the following structure: first set of columns of varying types is intended as meta data, second set of columns of the same type is intended as main data. tableMatrix combines strengths of data.table (access via bracket to the meta data part) and matrix (main data). It also stores dimensions of main data, thus allowing to combine rows of varying lengths into one object. As in tableList, tableMatrix can carry any additional aid data and data types groups.

Usage

1
2
tableMatrix(dataList, tabCol, matCol, dims = NULL, dimNames = NULL,
  aidData = list(), dataType = NULL)

Arguments

dataList

Dataset(s) in the form of data.frame or data.table or list of data.frames or data.tables. All datasets must have the same meta data columns, matrix parts can be different.

tabCol

Integer or character vector or list of these vectors. Specifies column names or indices of meta data part. For list input, names j or r can be used. List name j indicates that column names or indices are specified, name r indicates range of column names or indices. By default or when a vector is provided, j is used.

matCol

Integer or character vector or list of these vectors. Specifies column names or indices of main data part. For list input, names j or r can be used as in tabCol.

dims

Numeric vector or list of vectors. Specifies dimensions for the matDim part. By default with no dimension details given by user, main data is considered to be vectors with one dimension.

dimNames

Character vector. Specifies dimension names in matDim for each element of dims parameter. If not specified these names are generated automatically.

aidData

Aid structures generally in the form of a list.

dataType

Named list. Contains names of groups of attributes, elements are attributes which belong to the group.

Details

tableMatrix is a S3 class that consists of 4 parts. tab - table part - is used for storing meta data, mat - matrix part - for storing main data and matDim - dimensions part - for dimensions of main data. mat is a list of matrices. tab is a data.table. In tab first column tm.matN is the matrix number in mat, second column tm.matRow is the row in the matrix. matDim is data.table. In matDim for each matrix number tm.matN dimensions can be specified with user defined dimensions. dataType is a list which contains names of groups of attributes and vectors of attributes belonging to it. Default print of tableMatrix is the print of the tab part without tm.matN and tm.matRow columns.

Value

A tableMatrix object

See Also

getRowRepo.tableMatrix, getRowDim.tableMatrix, merge.tableMatrix, rbind.tableMatrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
data(images8By8)
dim(images8By8)

data(images10By10)
dim(images10By10)
images10By10DT <- data.table::as.data.table(images10By10)

# Generate tableMatrix from data.frame images8By8: use columns 1:3 as meta data and 
# columns 4:ncol(images8By8) as main data 
TM <- tableMatrix(images8By8, 1:3, 4:ncol(images8By8))
matDim(TM) # show matDim
tab(TM) # show meta data part of tableMatrix
head(mat(TM)[[1]]) # show head of main data part

# Generate tableMatrix from data.frame images8By8: use columns "direction" and "dimY"
# as meta data and columns 4:ncol(images8By8) as main data 
tableMatrix(images8By8, c("direction","dimY"), 4:ncol(images8By8))

# User defined dimensions with default names
TM <- tableMatrix(images8By8, c("direction","dimX","dimY"), 4:ncol(images8By8), c(8,8))
matDim(TM)

# User defined dimensions with custom names
dims <- c(8,8)
names(dims) <- c("dimX", "dimY")

TM <- tableMatrix(images8By8, 1:3, 4:ncol(images8By8), dims)
matDim(TM)

# tabCol and matCol list input with "j" option
# Column indices: first 3 columns in tab, rest in mat
tableMatrix(images8By8, list(j=1:3), list(j=4:ncol(images8By8)))
# Column names: columns "direction" and "dimY" in tab, 
# columns "pixel1" and "pixel2" in mat
tableMatrix(images8By8, list(j=c("direction","dimY")), list(j=c("pixel1","pixel2")))

# tabCol and matCol list input with "r" option
# Column indices: first 3 columns in tab, rest in mat
tableMatrix(images8By8, list(r=c(1,3)), list(r=c(4,ncol(images8By8))))
# Same with column names
tableMatrix(images8By8, list(r=c("direction","dimY")), list(r=c("pixel1","pixel100")))

# data.table as the start dataset
tableMatrix(images10By10DT, 1:3, 4:ncol(images10By10DT))

# data.frame and data.table with different main data parts -> two matrices in mat.
# Elements in tabCol and matCol lists correspond to images8By8 and images10By10DT
# respectively
TM <- tableMatrix(list(images8By8, images10By10DT),
list(r=c("direction","dimY"), j=c("direction","dimX","dimY")),
list(4:ncol(images8By8),4:ncol(images10By10DT)))
matDim(TM)
length(mat(TM)) # 2 matrices in mat

# User defined named dimensions
TM <- tableMatrix(list(images8By8, images10By10),
list(r=c("direction","dimY"), j=c("direction","dimX","dimY")),
list(c(4:ncol(images8By8)),c(4:ncol(images10By10))),list(c(8,8),c(10,10)),
dimNames =c("dimX", "dimY"))
matDim(TM)

# Same main data parts -> only one matrix in mat
TM <- tableMatrix(list(images8By8, images8By8), 
list(r=c("direction","dimY"), j=c("direction","dimX","dimY")),
list(j=4:ncol(images8By8),4:ncol(images8By8)))
matDim(TM)
length(mat(TM)) # 1 matrix in mat

# dataType support
TM <- tableMatrix(images10By10, 1:3, 4:ncol(images10By10), 
dataType=list("group1"="direction", "group2"=c("dimX","dimY")))
dataType(TM)

InferenceTechnologies/tableMatrix documentation built on May 8, 2019, 1:39 p.m.