## Basic Examples
mtcarsM <- qM(mtcars) # Matrix from data.frame
mtcarsDT <- qDT(mtcarsM) # data.table from matrix columns
mtcarsTBL <- qTBL(mtcarsM) # tibble from matrix columns
head(mrtl(mtcarsM, TRUE, "data.frame")) # data.frame from matrix rows, etc..
head(qDF(mtcarsM, "cars")) # Adding a row.names column when converting from matrix
head(qDT(mtcars, "cars")) # Saving row.names when converting data frame to data.table
head(qM(iris, "Species")) # Examples converting data to matrix, saving information
head(qM(GGDC10S, is.character)) # as rownames
head(qM(gv(GGDC10S, -(2:3)), 1:3, sep = "-")) # plm-style rownames
qDF(fmean(mtcars), c("cars", "mean")) # Data frame from named vector, with names
# mrtl() and mctl() are very useful for iteration over matrices
# Think of a coordninates matrix e.g. from sf::st_coordinates()
coord <- matrix(rnorm(10), ncol = 2, dimnames = list(NULL, c("X", "Y")))
# Then we can
for (d in mrtl(coord)) {
cat("lon =", d[1], ", lat =", d[2], fill = TRUE)
# do something complicated ...
}
rm(coord)
## Factors
cylF <- qF(mtcars$cyl) # Factor from atomic vector
cylF
# Factor to numeric conversions
identical(mtcars, as_numeric_factor(dapply(mtcars, qF)))
Run the code above in your browser using DataLab