I have a data set with many date columns which have index. How to easily order them in the dataframe. Appreciate the help. Thanks
data <- data.frame(x1 = 1:10,
date3 = c("2020-01-25", "2021-02-10","2021-03-15","2020-04-09","2021-05-11","2020-06-07","2021-08-08", NA,"2020-10-18", "2021-11-11"),
date1 = c("2020-02-25", "2021-04-10","2021-04-15","2020-05-09","2021-06-11","2020-07-07","2021-09-08", NA,"2020-11-18", "2021-12-11"),
date4 = c("2020-01-25", "2021-02-10","2021-03-15","2020-04-09","2021-05-11",NA,"2021-09-08", NA,"2020-05-18", "2021-10-11"),
date2 = c("2020-01-25", "2021-02-10","2021-03-15","2020-04-09","2021-05-11","2020-06-07","2021-08-08", NA,"2020-10-18", "2021-11-11"),
x4 = factor(c("B", "B", "A", "F", "A", "B", "A", "B","A", "B")),
stringsAsFactors = FALSE)
# one way is this, but is there any other easy way?
data<-data.table::setcolorder(data, c("x1","date1","date2","date3","date4"
))