Re: [R] interval between specific characters in a string...

2022-12-03 Thread Bert Gunter
Thanks. Very informative. I certainly missed this. -- Bert On Sat, Dec 3, 2022 at 3:49 PM Hervé Pagès wrote: > On 03/12/2022 07:21, Bert Gunter wrote: > > Perhaps it is worth pointing out that looping constructs like lapply() > can > > be avoided and the procedure vectorized by mimicking Martin

Re: [R] interval between specific characters in a string...

2022-12-03 Thread avi.e.gross
This may be a fairly dumb and often asked question about some functions like strsplit() that return a list of things, often a list of ONE thing that be another list or a vector and needs to be made into something simpler.. The examples shown below have used various methods to convert the result

Re: [R] interval between specific characters in a string...

2022-12-03 Thread Hervé Pagès
On 03/12/2022 07:21, Bert Gunter wrote: Perhaps it is worth pointing out that looping constructs like lapply() can be avoided and the procedure vectorized by mimicking Martin Morgan's solution: ## s is the string to be searched. diff(c(0,grep('b',strsplit(s,'')[[1]]))) However, Martin's solutio

Re: [R] interval between specific characters in a string...

2022-12-03 Thread Bert Gunter
Perhaps it is worth pointing out that looping constructs like lapply() can be avoided and the procedure vectorized by mimicking Martin Morgan's solution: ## s is the string to be searched. diff(c(0,grep('b',strsplit(s,'')[[1]]))) However, Martin's solution is simpler and likely even faster as the

Re: [R] interval between specific characters in a string...

2022-12-03 Thread Rui Barradas
Às 17:18 de 02/12/2022, Evan Cooch escreveu: Was wondering if there is an 'efficient/elegant' way to do the following (without tidyverse). Take a string abaaabbabaaab Its easy enough to count the number of times the character 'b' shows up in the string, but...what I'm looking for is outpu