Keep rows order in data.frame when a function is applied to it.

keep_df_order(df, fun, ...)

Arguments

df

the data.frame that will be changed by the function fun

fun

the function that will be applied

...

other parameters to fun

Source of inspiration

A comment from landroni (2017-09-23 at 15:59) on http://stackoverflow.com

Examples

if (FALSE) {
df.1 = data.frame(object = c('A', 'B', 'D', 'F', 'C'), class = c(2, 1, 2, 3, 1))
df.2 = data.frame(class = c(1, 2, 3), prob = c(0.5, 0.7, 0.3))
merge(df.1, df.2)
keep_df_order(df.1, merge, df.2, suffixes = c("_x","_y"))
}