I have data that I want to display in 5% increments, such as 5-10%, 10-15%, etc. To do this, I have a data frame that stores them as a factor, with the levels being the mid
You could use a hidden column with the numeric value of the factor and sort the factors according to that hidden column:
library('DT')
value <- factor(c(7.5, 12.5, 7.5, 17.5),
levels = c(7.5, 12.5, 17.5),
labels = c('5-10%', '10-15%', '15-20%'))
example <- data.frame(name = c('A', 'B', 'C', 'D'),
value = value,
levels=as.numeric(value))
datatable(example,
rownames = FALSE,
options = list(columnDefs=list(list(orderData=2,targets=1),
list(visible=FALSE,targets=2))))