Skip to content

Commit

Permalink
Updated vlookup function with more pragmatic parameter names.
Browse files Browse the repository at this point in the history
  • Loading branch information
grabear committed Jan 2, 2019
1 parent 72e1be9 commit 70b96ce
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ transformer <- function(.data, func, by = "column", ids = NULL, header_name = NU

#' @title Mock Excel "VlookUp" Function
#' @description A function that mimicks excels vlookup, but for R's dataframe.
#' @param lookup_data A vector of items to look up.
#' @param lookup_vector A vector of items to look up.
#' @param df The dataframe to search.
#' @param match_data The column name to search in the dataframe.
#' @param return_data The column of data to return when matched.
#' @param match_var The column name to search in the dataframe.
#' @param return_var The column of data to return when matched.
#' @return A vector that contains the items of interest.
#' @pretty_print TRUE
#' @details A function that works like the VLOOKUP function in excel. This function was
Expand All @@ -335,10 +335,10 @@ transformer <- function(.data, func, by = "column", ids = NULL, header_name = NU
#' @export
#' @family Data Manipulators
#' @rdname vlookup
vlookup <- function(lookup_data, df, match_data, return_data) {
vlookup <- function(lookup_vector, df, match_var, return_var) {
# TODO: Update the way this returns data. Allow it to add data to a new column.
m <- match(lookup_data, df[[match_data]])
df[[return_data]][m]
m <- match(lookup_vector, df[[match_var]])
df[[return_var]][m]
}

#' @title Create a table from a data frame
Expand Down

0 comments on commit 70b96ce

Please sign in to comment.