Learn R Programming

R2DT (version 0.2)

sortByRowIndexDT: Order the rows of a data.table object by index

Description

Order the rows of a data.table object by index

Usage

sortByRowIndexDT(inputDT, rowIndices)

Arguments

inputDT

data.table object containing the data of interest. This is an obligatory argument, without default value.

rowIndices

Integer vector that contains the row indices according to which the 'inputDT' object should be ordered. This is an obligatory argument, without default value.

Value

The 'inputDT' data.table object, ordered according to the 'rowIndices' argument. This function assumes that the length of the 'rowIndices' argument is correspond to the number of rows of the 'inputDT' argument. If the length of the 'rowIndices' argument is smaller than the number of rows of the 'inputDT' argument, the values of the 'rowIndices' argument are recycled until the as many indices as number of rows of the 'inputDT' argument is obtained.

Examples

Run this code
# NOT RUN {
library(data.table)
inputDT <- as.data.table(data.frame(x = 10:1, y = LETTERS[1:10]))
asFactorDT(inputDT, c('y'))
inputDT
sortByRowIndexDT(inputDT, 10:1)
inputDT
# }

Run the code above in your browser using DataLab