| create_rowvec_byname | R Documentation |
This function takes data in the .dat and creates row vectors.
create_rowvec_byname(
.dat,
dimnames = NA,
rowname = NA,
matrix_class = c("matrix", "Matrix")
)
.dat |
Data to be converted to row vectors. |
dimnames |
The dimension names to be used for creating the row vector, in a list format, or as a data frame column containing a list of the dimension names to be used for each observation. |
rowname |
The name of the row of the row vector. |
matrix_class |
One of "matrix" or "Matrix".
"matrix" creates a |
The row and column names in the resulting row vector are taken from
rowname and the names of .dat.
If set, dimnames overrides rowname and the names of .dat.
Row types and column types are taken from the row type and column type attributes of .dat.
This function is a "byname" function that can accept a single number,
a vector, a list, or a data frame in .dat.
A row vector, a list of row vectors, or a data frame column of row vectors, depending on the
values of .dat and class.
# Works with single numbers
create_rowvec_byname(c(c1 = 1) %>% setrowtype("rt") %>% setcoltype("ct"), rowname = "r1")
# Works with vectors
create_rowvec_byname(c(c1 = 1, c2 = 2), rowname = "r1")
# Works with a list
create_rowvec_byname(list(c(c1 = 1, c2 = 2), c(C1 = 3, C2 = 4, C3 = 5)),
rowname = list("r1", "R1"))
# Works in a tibble, too.
# (Must be a tibble, not a data frame, so that names are preserved.)
dat <- list(c(c1 = 1),
c(C1 = 2, C2 = 3),
c(c1 = 1, c2 = 2, c3 = 3, c4 = 4, c5 = 5, c6 = 6))
rnms <- list("r1", "R1", "r1")
df1 <- tibble::tibble(dat, rnms)
df1
df1 <- df1 %>%
dplyr::mutate(
rowvec_col = create_rowvec_byname(dat, rowname = rnms)
)
df1$rowvec_col[[1]]
df1$rowvec_col[[2]]
df1$rowvec_col[[3]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.