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

Bob Rudis bob at rud.is
Wed Oct 19 17:26:48 CEST 2016


purrr::map(paste0(letters, collapse=""), ~purrr::map2_chr(.,
1:nchar(.), ~substr(.x, 1, .y)))[[1]]

seems to crank really fast at least on my system

what did you try that was slow?

On Wed, Oct 19, 2016 at 11:01 AM, 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
>
>
> --
> Witold Eryk Wolski
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list