Use paste to combine letters instead or loops. R

concatenation, loops, paste, r

Solution

Here is one way to do this

sapply(1:7, function(i) {
  paste(letters[i:(i+3)], collapse = '')
})

Problem

I'm a newbie to R, but I'm trying to make a sliding window in R. Using loops I can it like this, but this gets very inefficient. ``` results=c(1:7) letters=c("A","B","C","D","E","F","G","H","I","J") for(i in 1:7){ results[i]=paste(letters[i:(i+3)],collapse="") } ``` How can I use an apply function to get the same output?

Original source