I'm trying to create a function able to return various versions of the same string but with blank spaces between the letters.
input <- "word"
We first break the string into every character using
strsplit. We then
append an empty space at every position using
input <- "word" input_break <- strsplit(input, "")[] c(input, sapply(seq(1,nchar(input)-1), function(x) paste0(append(input_break, " ", x), collapse = ""))) # "word" "w ord" "wo rd" "wor d"
?append gives us
append(x, values, after = length(x))
x is the vector,
value is the value to be inserted (here
" " ) and
after is after which place you want to insert the