[R] create n suffixes of length 1:n from string of length n
jdnewmil at dcn.davis.ca.us
Wed Oct 19 18:41:10 CEST 2016
When I replace length with nchar, it works fine for me without mapply.
substr( rep( s, nchar(s) ), 1, seq.int( nchar(s) ) )
Sent from my phone. Please excuse my brevity.
On October 19, 2016 9:36:25 AM PDT, David Winsemius <dwinsemius at comcast.net> wrote:
>> On Oct 19, 2016, at 8:44 AM, Jeff Newmiller
><jdnewmil at dcn.davis.ca.us> wrote:
>> These don't look like "suffixes" to me, but whatever.
>> s <- "abc"
>> substr( rep( s, length(s) ), 1, seq.int( length(s) ) )
>I suspect that `nchar` was meant instead of `length` but it still
>failed. How about:
>lets <- paste0(letters,collapse=TRUE)
>unname( mapply( substr, lets, 1, 1:26) ) # mapply will recycle
More information about the R-help