I have a dataframe with a names column, these names are repeated (same people have multiple row entries). I would like to order the data frame based on an order of my choosing. For example, here is a simplified version of the problem:
df <- data.frame(index = rep(1, 12), name = sample( LETTERS[1:3], 12, replace = TRUE) )
target <- c( 'C', 'A', 'B' )
so what i want is to order df
so that all the rows with 'C' are first, followed by the 'A' rows then the 'B' rows.
One way to do it is to subset the dataframe into the seperate cases, then use rbind
, which works, but this doesn't seem efficient for large dataframes with many different names