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 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.

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 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".

stringsAsFactors

logical vector of length 1 specifying if v should be converted to a factor in the case that typeof is character.

check

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).

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")

[Package str2str version 1.0.0 Index]