[R] create n suffixes of length 1:n from string of length n

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed Oct 19 17:44:34 CEST 2016


These don't look like "suffixes" to me,  but whatever.

s <- "abc"
substr( rep( s, length(s) ), 1, seq.int( length(s) ) )

-- 
Sent from my phone. Please excuse my brevity.

On October 19, 2016 8:01:10 AM PDT, Witold E Wolski <wewolski at gmail.com> wrote:
>Is there a build in function, which creates n suffixes of length 1:n
>from string of length n?
>e.g given abcd
>
>produces
>"a"
>"ab"
>"abc"
>
>
>FAST.
>
>equally nice to have would be:
>
>e.g.
>given c("a", "b", "c")
>produces
>"a"
>"a","b"
>"a","b","c"
>
>Thank you
>Witold



More information about the R-help mailing list