optimized_arrange <- function(x, n = NULL) {
if (!is.numeric(n)) {
stop("Provide n!")
}
if (is.data.frame(x)) {
remain <- seq(nrow(x))
} else {
remain = seq_along(x)
}
new_order <- c()
while (length(remain) != 0) {
new_order <- c(new_order, head(remain, n), rev(tail(remain, n)))
remain <- base::setdiff(remain, new_order)
}
new_order <- unique(new_order)
if (is.data.frame(x)) {
x[new_order, ]
} else {
x[new_order]
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.