R/df.2.named.vector.R

Defines functions df.2.named.vector

Documented in df.2.named.vector

#' Data frame to named vector
#'
#' Turns the two first columns of a data frame into a named vector, taking the
#' values from the second and the names from the first column.
#'
#' @param .data a data frame with at least two columns
#'
#' @return a named vector
#' @export
#'
#' @examples
#' data <- data.frame(names = c("one", "two", "three"), values = 1:3)
#' data
#' df.2.named.vector(data)

df.2.named.vector <- function(.data) {
    x <- as.character(.data[,2])
    names(x) <- as.character(.data[,1])

    return(x)
}
michaja/quitte documentation built on May 22, 2019, 9:53 p.m.