Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Last active June 22, 2020 14:58
Show Gist options
  • Save mrdwab/fd8c654cbc6c27d1da2c91ce61cffd60 to your computer and use it in GitHub Desktop.
Save mrdwab/fd8c654cbc6c27d1da2c91ce61cffd60 to your computer and use it in GitHub Desktop.
lengthen <- function(vec, length) {
vec[sort(rep(seq_along(vec), length.out = length))]
}
lengthen(a2, length(a1))
# [1] 1 1 1 3 3 3 4 4 5 5
lengthen(a3, length(a1))
# [1] 1 1 2 2 5 5 6 6 9 9
lengthen(a4, length(a1))
# [1] 5 5 5 1 1 1 3 3 4 4
s1 <- c("a", "c", "b")
f1 <- factor(c("g", "l", "c", "a"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment