R/insert_miss_rows.R

Defines functions insert_miss_rows

Documented in insert_miss_rows

#' Function for creating new rows with potentially missing information 
#'
#' This function allows you to merge subsets 
#' @param dtfr Total dataframe 
#' @param col_names Names of columns that should be extended
#' @keywords merging expansion
#' @export
#' @examples
#' insert_miss_rows()
insert_miss_rows <- function(dtfr, col_names){
    
    # Create subset for identifying unique observations 
    dtfr_subset <- dtfr[, col_names]
    
    # Create unique combinations
    df <- unique_comb(dtfr_subset)
    
    # Merge the total combination and original dataset to create new rows
    df_new <- merge(df, dtfr, all.x = T, by = col_names)
    
    # Return the updated data frame with formerly missing rows
    return(df_new)
}
EriksenJ/FunctionsJE documentation built on May 7, 2019, 7:43 a.m.