v2d {str2str} | R Documentation |
(Atomic) Vector to Data-Frame
Description
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.
Usage
v2d(v, along = 2, rtn.dim.nm = NULL, stringsAsFactors = FALSE, check = TRUE)
Arguments
v |
(atomic) vector. |
along |
numeric vector of length 1 that is equal to either 1 or 2 specifying
which dimension to bind |
rtn.dim.nm |
character vector of length 1 specifying what dimname to use
for the dimension of length 1 in the returned data.frame. If |
stringsAsFactors |
logical vector of length 1 specifying if |
check |
logical vector of length 1 specifying whether to check the structure
of the input arguments. For example, check whether |
Value
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)
.
Examples
x <- setNames(mtcars[, "mpg"], nm = row.names(mtcars))
v2d(x)
v2d(v = x, along = 1)
v2d(v = x, rtn.dim.nm = "mpg")