Learn R Programming

usefun (version 0.5.2)

add_vector_to_df: Add vector to a (n x 2) data frame

Description

Given a vector, adds each value and its corresponding name to a data frame of 2 columns as new rows, where the name fills in the 1st column and the value the 2nd column.

Usage

add_vector_to_df(df, vec)

Value

a data.frame with additional rows and each element as a character.

Arguments

df

data.frame, with n rows and 2 columns

vec

a vector

Examples

Run this code
df = data.frame(c(0,0,1), c(0,0,2))
vec = 1:3
names(vec) = c("a","b","c")

add_vector_to_df(df, vec)

Run the code above in your browser using DataLab