Learn R Programming

exams.forge (version 1.0.10)

vec2mat: Vector to Matrix Conversion

Description

Converts a vector to a horizontal or vertical matrix and sets row- or colnames. If rownames or colnames are given, then existing row names or column names are overwritten.

Usage

vec2mat(x, colnames = NULL, rownames = NULL, horizontal = TRUE)

to_mat(x, colnames = NULL, rownames = NULL, horizontal = TRUE)

Value

A matrix

Arguments

x

vector

colnames

character: vector of new column names (default: NULL)

rownames

character: vector of new row names (default: NULL)

horizontal

logical: horizontal or vertical matrix (default: TRUE)

Examples

Run this code
x <- runif(5)
vec2mat(x)
vec2mat(x, horizontal=FALSE)

Run the code above in your browser using DataLab