I would like to reorder rows in a dataframe based on a specific order. Here is a dummy dataframe (in the long format) that pretty much looks like my data:
library(ggplot2)
library(dplyr)
#data frame
MV<-c(rnorm(50,mean=10, sd=1),rnorm(50,mean=9, sd=1))
ML<-c(rnorm(50,mean=12, sd=1),rnorm(50,mean=10, sd=1))
NL<-c(rnorm(50,mean=10, sd=1),rnorm(50,mean=8,sd=1))
ID<-rep(1:50,1)
Type<-rep(c("BM","NBM"),times=1, each=50)
df<-data.frame(ID, Type, MV, ML, NL)
#Here is the dataframe:
df.gat<-gather(df, "Tests", "Value", 3:5)
My data is already in the long format to start with (df.gat). The code before that is just to get you a similar dataframe.
Basically, I'd like to have my data ordered in my dataframe in the following order: NL, MV, and ML
I have tried various methods such as the following Reorder rows using custom order or How does one reorder columns in a data frame? which are not very convenient considering the number of rows in my dataset.
The solution also needs to work if some participants didn't do all the tests.
Any solution?