R/col_to_vec.R

Defines functions col_to_vec

Documented in col_to_vec

#' This converts a data frame column to a vector, similar to the "$" operator in base R.
#' @import dplyr
#' @import magrittr
#' @import stringr
#' @import purrr
#' @param col, the data frame column
#' @return vector with elements of the column
#' @export

col_to_vec <- function(col) {
  if(ncol(col) != 1) {
    stop(paste("Need exactly one column. There are", ncol(col), "columns"))
  }
  vector <- c()
  for(i in 1:nrow(col)) {
    vector <- append(vector, col[i, names(col)[1]])
  }
  return()
}
kingsuching/Frost2021Package documentation built on March 19, 2022, 11:51 p.m.