R/reorder_df_function.R

Defines functions reorder_df

Documented in reorder_df

#' @title reorder_df
#'
#' @description Reorders the rows of one dataframe according to another vector (id vector)
#' @param df dataframe to reorder
#' @param col_sort column on which the rows will be reordered
#' @param reorder_data vector with the new order
#' @export
#' @return Reordered dataframe
#' @examples
#'df <- data.frame(a = letters[1:3],b = LETTERS[4:6],c = 7:9)
#'
#'reorder_data<-c("c","a","b")
#'
#'df_new<-reorder_df(df,"a",reorder_data)
#'
#'df_new
#'
reorder_df<-function(df,col_sort,reorder_data){

  df_new<-df[order(match(df[, col_sort],reorder_data)),]
}

Try the ITNr package in your browser

Any scripts or data that you put into this service are public.

ITNr documentation built on March 13, 2020, 1:48 a.m.