<p>You can try something like the following:</p>
<pre><code>s <- "XOVEWVJIEWNIGOIWENVOIWEWVWEW" # Original string
l <- seq(from=5, to=nchar(s), by=5) # Calculate the location where to chop
# Add sentinels 0 (beginning of string) and nchar(s) (end of string)
# and take substrings. (Thanks to @flodel for the condense expression)
mapply(substr, list(s), c(0, l) + 1, c(l, nchar(s)))
<pre><code> "XOVEW" "VJIEW" "NIGOI" "WENVO" "IWEWV" "WEW"
<p>Now you can <code>paste</code> the resulting vector (with <code>collapse=' '</code>) to obtain a single string with spaces.</p>
<p>This tip was originally posted on <a href="http://stackoverflow.com/questions/26497583/Split%20a%20string%20every%205%20characters/26497660">Stack Overflow</a>.</p>
Get New Tutorials Delivered to Your Inbox
New tutorials will be sent to your Inbox once a week.