-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
Hi Tomaž. I know the typical idiom for scrambling letters in R involves strsplit
.
Here's another approach: use charToRaw
and rawToChar
instead.
# Helper function. Can also be placed inside of WordScrambler() instead or be an
# anonymous function in the `tapply` step.
fun <- function(x) rawToChar(sample(x))
WordScrambler <- function(text) {
w <- charToRaw(text)
words <- cumsum(w == "20")
tolower(paste(tapply(w[w != "20"], words[w != "20"], fun), collapse = " "))
}
Metadata
Metadata
Assignees
Labels
No labels