v2m
converts an (atomic) vector to a single row or single column data.frame.
The benefit of v2m
over as.data.frame.vector
is that the dimension
along which the vector is binded can be either rows or columns, whereas in
as.data.frame.vector
it can only be binded along a column, and that
v2m
will keep the names of v
in the dimnames of the returned
data.frame.
v2d(v, along = 2, rtn.dim.nm = NULL, stringsAsFactors = FALSE, check = TRUE)
data.frame with typeof = typeof(v)
. If along
= 1, then the
dimensions = c(1L, length(v))
and dimnames = list(rtn.dim.nm, names(v))
.
If along
= 2, then the dimensions = c(length(v), 1L)
and dimnames =
list(names(v), rtn.dim.nm)
.
(atomic) vector.
numeric vector of length 1 that is equal to either 1 or 2 specifying
which dimension to bind v
along. 1 means that v
is binded along
rows (i.e., dimension 1) into a one row data.frame. 2 means that v
is binded
along columns (i.e., dimension 2) into a one column data.frame.
character vector of length 1 specifying what dimname to use
for the dimension of length 1 in the returned data.frame. If along
= 1,
then rtn.dim.nm
will be the single rowname. If along
= 2, then
rtn.dim.nm
will be the single colname. If NULL, then the dimension of
length 1 will be created by default with data.frame
internally, which
will have the rowname be "1" and the colname "V1".
logical vector of length 1 specifying if v
should be converted to a factor in the case that typeof is character.
logical vector of length 1 specifying whether to check the structure
of the input arguments. For example, check whether v
is an atomic vector.
This argument is available to allow flexibility in whether the user values
informative error messages (TRUE) vs. computational efficiency (FALSE).
x <- setNames(mtcars[, "mpg"], nm = row.names(mtcars))
v2d(x)
v2d(v = x, along = 1)
v2d(v = x, rtn.dim.nm = "mpg")
Run the code above in your browser using DataLab