
Last chance! 50% off unlimited learning
Sale ends in
Convert common data types quickly, without method dispatch and extensive checks:
qDF
and qDT
convert vectors, matrices, higher-dimensional arrays and suitable lists to data.frame
and data.table
respectively.
qM
converts vectors, higher-dimensional arrays, data.frames and suitable lists to matrix.
mctl
and mrtl
are exported C++ functions that column- or row-wise convert a matrix to list, data.frame
or data.table
. They are used internally by qDF
and qDT
, dapply
, BY
, etc...
qF
converts atomic vectors to factor.
qG
is a programmers function that converts atomic vectors to a quick-group (class attribute 'qG') - a kind of factor light which is just an integer vector with an attribute 'N.groups' indicating the number of groups. (Thus saving time consumed by converting the levels of a numeric vector to character).
qDF(X, row.names.col = FALSE)
qDT(X, row.names.col = FALSE)
qM(X)
mctl(X, names = FALSE, ret = 0L)
mrtl(X, names = FALSE, ret = 0L)
qF(x, ordered = TRUE, na.exclude = TRUE)
qG(x, ordered = TRUE, na.exclude = TRUE)
a vector, matrix, higher-dimensional array, data.frame or list. mctl
and mrtl
only take matrices.
a atomic vector or factor.
should a column capturing names or row.names be added? i.e. when converting atomic objects to data.frame or data.frame to data.table. Can be logical TRUE
, which will add a column "row.names"
in front, or can supply a name for the column i.e. "column1"
.
logical. TRUE
sorts the levels and returns an ordered factor.
logical. Should the list be named?
integer. 3 return options: 0L - return a list, 1L - return a data.frame, 2L - return a data.table.
logical. TRUE
preserves missing values in character or numeric vectors (i.e. no underlying integer is generated to represent NA
, and functions like na_rm
will remove missing values from the factor). FALSE
creates an integer for NA
and also attaches a class 'na.included', which will make computations with collapse
functions faster (since no NA
checking is required). Note that in both cases a 'NA'
level is attached, so this option only concerns the underlying integer vector and the response to functions dealing with missing values (like na_rm
).
qDF
- returns a data.frame
qDT
- returns a data.table
qM
- returns a matrix
mctl
, mrtl
- return a list, data.frame or data.table
qF
- returns a factor
qG
- returns a quick-group (= integer vector)
# NOT RUN {
mtcarsM <- qM(mtcars) # Matrix from data.frame
mtcarsDT <- qDT(mtcarsM) # data.table from matrix columns
mrtl(mtcarsM, TRUE, 2L) # data.table from matrix rows, etc...
qDF(mtcarsM, "cars") # Adding a row.names column when converting from matrix
qDT(mtcars, "cars") # Saving row.names when converting data.frame to data.table
cylF <- qF(mtcars$cyl) # Factor from atomic vector
cylG <- qG(mtcars$cyl) # Quick-group from atomic vector
cylG # See the simple structure of this object
# }
Run the code above in your browser using DataLab